[Scummvm-cvs-logs] SF.net SVN: scummvm:[34197] scummvm/trunk/backends
fingolfin at users.sourceforge.net
fingolfin at users.sourceforge.net
Wed Aug 27 22:31:26 CEST 2008
Revision: 34197
http://scummvm.svn.sourceforge.net/scummvm/?rev=34197&view=rev
Author: fingolfin
Date: 2008-08-27 20:31:22 +0000 (Wed, 27 Aug 2008)
Log Message:
-----------
FSNode code: Merged most versions of lastPathComponent() into one new AbstractFilesystemNode::lastPathComponent() method, with customizable path separator character
Modified Paths:
--------------
scummvm/trunk/backends/fs/abstract-fs.h
scummvm/trunk/backends/fs/ds/ds-fs.cpp
scummvm/trunk/backends/fs/palmos/palmos-fs.cpp
scummvm/trunk/backends/fs/posix/posix-fs.cpp
scummvm/trunk/backends/fs/ps2/ps2-fs.cpp
scummvm/trunk/backends/fs/psp/psp-fs.cpp
scummvm/trunk/backends/fs/symbian/symbian-fs.cpp
scummvm/trunk/backends/fs/wii/wii-fs.cpp
scummvm/trunk/backends/fs/windows/windows-fs.cpp
scummvm/trunk/backends/module.mk
scummvm/trunk/backends/platform/dc/dc-fs.cpp
Added Paths:
-----------
scummvm/trunk/backends/fs/abstract-fs.cpp
Added: scummvm/trunk/backends/fs/abstract-fs.cpp
===================================================================
--- scummvm/trunk/backends/fs/abstract-fs.cpp (rev 0)
+++ scummvm/trunk/backends/fs/abstract-fs.cpp 2008-08-27 20:31:22 UTC (rev 34197)
@@ -0,0 +1,39 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * $URL$
+ * $Id$
+ */
+
+#include "backends/fs/abstract-fs.h"
+
+const char *AbstractFilesystemNode::lastPathComponent(const Common::String &str, const char sep) {
+ if(str.empty())
+ return "";
+
+ const char *start = str.c_str();
+ const char *cur = start + str.size() - 2;
+
+ while (cur >= start && *cur != sep) {
+ --cur;
+ }
+
+ return cur + 1;
+}
Property changes on: scummvm/trunk/backends/fs/abstract-fs.cpp
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:keywords
+ Date Rev Author URL Id
Added: svn:eol-style
+ native
Modified: scummvm/trunk/backends/fs/abstract-fs.h
===================================================================
--- scummvm/trunk/backends/fs/abstract-fs.h 2008-08-27 19:29:41 UTC (rev 34196)
+++ scummvm/trunk/backends/fs/abstract-fs.h 2008-08-27 20:31:22 UTC (rev 34197)
@@ -72,6 +72,19 @@
*/
virtual AbstractFilesystemNode *getParent() const = 0;
+ /**
+ * Returns the last component of a given path.
+ *
+ * Examples:
+ * /foo/bar.txt would return /bar.txt
+ * /foo/bar/ would return /bar/
+ *
+ * @param str String containing the path.
+ * @param sep character used to separate path components
+ * @return Pointer to the first char of the last component inside str.
+ */
+ static const char *lastPathComponent(const Common::String &str, const char sep);
+
public:
/**
* Destructor.
@@ -154,4 +167,6 @@
*/
};
+
+
#endif //BACKENDS_ABSTRACT_FS_H
Modified: scummvm/trunk/backends/fs/ds/ds-fs.cpp
===================================================================
--- scummvm/trunk/backends/fs/ds/ds-fs.cpp 2008-08-27 19:29:41 UTC (rev 34196)
+++ scummvm/trunk/backends/fs/ds/ds-fs.cpp 2008-08-27 20:31:22 UTC (rev 34197)
@@ -798,25 +798,3 @@
}
} // namespace DS
-
-/**
- * Returns the last component of a given path.
- *
- * Examples:
- * /foo/bar.txt would return /bar.txt
- * /foo/bar/ would return /bar/
- *
- * @param str String containing the path.
- * @return Pointer to the first char of the last component inside str.
- */
-const char *lastPathComponent(const Common::String &str) {
- const char *start = str.c_str();
- const char *cur = start + str.size() - 2;
-
- while (cur >= start && *cur != '/' && *cur != '\\') {
- --cur;
- }
-
- return cur + 1;
-}
-
Modified: scummvm/trunk/backends/fs/palmos/palmos-fs.cpp
===================================================================
--- scummvm/trunk/backends/fs/palmos/palmos-fs.cpp 2008-08-27 19:29:41 UTC (rev 34196)
+++ scummvm/trunk/backends/fs/palmos/palmos-fs.cpp 2008-08-27 20:31:22 UTC (rev 34197)
@@ -80,30 +80,6 @@
static void addFile(AbstractFSList &list, ListMode mode, const Char *base, FileInfoType* find_data);
};
-/**
- * Returns the last component of a given path.
- *
- * Examples:
- * /foo/bar.txt would return /bar.txt
- * /foo/bar/ would return /bar/
- *
- * @param str String containing the path.
- * @return Pointer to the first char of the last component inside str.
- */
-const char *lastPathComponent(const Common::String &str) {
- if(str.empty())
- return "";
-
- const char *start = str.c_str();
- const char *cur = start + str.size() - 2;
-
- while (cur >= start && *cur != '/') {
- --cur;
- }
-
- return cur + 1;
-}
-
void PalmOSFilesystemNode::addFile(AbstractFSList &list, ListMode mode, const char *base, FileInfoType* find_data) {
PalmOSFilesystemNode entry;
bool isDir;
@@ -138,7 +114,7 @@
PalmOSFilesystemNode::PalmOSFilesystemNode(const String &p) {
_path = p;
- _displayName = lastPathComponent(_path);
+ _displayName = lastPathComponent(_path, '/');
UInt32 attr;
FileRef handle;
@@ -215,13 +191,13 @@
if (!_isPseudoRoot) {
const char *start = _path.c_str();
- const char *end = lastPathComponent(_path);
+ const char *end = lastPathComponent(_path, '/');
p = new PalmOSFilesystemNode();
p->_path = String(start, end - start);
p->_isValid = true;
p->_isDirectory = true;
- p->_displayName = lastPathComponent(p->_path);
+ p->_displayName = lastPathComponent(p->_path, '/');
p->_isPseudoRoot =(p->_path == "/");
}
Modified: scummvm/trunk/backends/fs/posix/posix-fs.cpp
===================================================================
--- scummvm/trunk/backends/fs/posix/posix-fs.cpp 2008-08-27 19:29:41 UTC (rev 34196)
+++ scummvm/trunk/backends/fs/posix/posix-fs.cpp 2008-08-27 20:31:22 UTC (rev 34197)
@@ -37,31 +37,6 @@
#endif
-
-/**
- * Returns the last component of a given path.
- *
- * Examples:
- * /foo/bar.txt would return /bar.txt
- * /foo/bar/ would return /bar/
- *
- * @param str String containing the path.
- * @return Pointer to the first char of the last component inside str.
- */
-const char *lastPathComponent(const Common::String &str) {
- if(str.empty())
- return "";
-
- const char *start = str.c_str();
- const char *cur = start + str.size() - 2;
-
- while (cur >= start && *cur != '/') {
- --cur;
- }
-
- return cur + 1;
-}
-
void POSIXFilesystemNode::setFlags() {
struct stat st;
@@ -93,7 +68,7 @@
_path = p;
}
- _displayName = lastPathComponent(_path);
+ _displayName = lastPathComponent(_path, '/');
if (verify) {
setFlags();
@@ -224,7 +199,7 @@
return 0;
const char *start = _path.c_str();
- const char *end = lastPathComponent(_path);
+ const char *end = lastPathComponent(_path, '/');
#ifdef __OS2__
if (end == start)
Modified: scummvm/trunk/backends/fs/ps2/ps2-fs.cpp
===================================================================
--- scummvm/trunk/backends/fs/ps2/ps2-fs.cpp 2008-08-27 19:29:41 UTC (rev 34196)
+++ scummvm/trunk/backends/fs/ps2/ps2-fs.cpp 2008-08-27 20:31:22 UTC (rev 34197)
@@ -100,28 +100,6 @@
virtual AbstractFilesystemNode *getParent() const;
};
-/**
- * Returns the last component of a given path.
- *
- * @param str String containing the path.
- * @return Pointer to the first char of the last component inside str.
- */
-const char *lastPathComponent(const Common::String &str) {
- if (str.empty())
- return "";
-
- const char *start = str.c_str();
- const char *cur = start + str.size() - 2;
-
- while (cur >= start && *cur != '/' && *cur != ':') {
- --cur;
- }
-
- printf("romeo : lastPathComponent = %s\n", cur + 1);
-
- return cur + 1;
-}
-
Ps2FilesystemNode::Ps2FilesystemNode() {
_isDirectory = true;
_isRoot = true;
Modified: scummvm/trunk/backends/fs/psp/psp-fs.cpp
===================================================================
--- scummvm/trunk/backends/fs/psp/psp-fs.cpp 2008-08-27 19:29:41 UTC (rev 34196)
+++ scummvm/trunk/backends/fs/psp/psp-fs.cpp 2008-08-27 20:31:22 UTC (rev 34197)
@@ -71,30 +71,6 @@
virtual AbstractFilesystemNode *getParent() const;
};
-/**
- * Returns the last component of a given path.
- *
- * Examples:
- * /foo/bar.txt would return /bar.txt
- * /foo/bar/ would return /bar/
- *
- * @param str String containing the path.
- * @return Pointer to the first char of the last component inside str.
- */
-const char *lastPathComponent(const Common::String &str) {
- if(str.empty())
- return "";
-
- const char *start = str.c_str();
- const char *cur = start + str.size() - 2;
-
- while (cur >= start && *cur != '/') {
- --cur;
- }
-
- return cur + 1;
-}
-
PSPFilesystemNode::PSPFilesystemNode() {
_isDirectory = true;
_displayName = "Root";
@@ -106,7 +82,7 @@
assert(p.size() > 0);
_path = p;
- _displayName = lastPathComponent(_path);
+ _displayName = lastPathComponent(_path, '/');
_isValid = true;
_isDirectory = true;
@@ -176,7 +152,7 @@
return 0;
const char *start = _path.c_str();
- const char *end = lastPathComponent(_path);
+ const char *end = lastPathComponent(_path, '/');
return new PSPFilesystemNode(String(start, end - start), false);
}
Modified: scummvm/trunk/backends/fs/symbian/symbian-fs.cpp
===================================================================
--- scummvm/trunk/backends/fs/symbian/symbian-fs.cpp 2008-08-27 19:29:41 UTC (rev 34196)
+++ scummvm/trunk/backends/fs/symbian/symbian-fs.cpp 2008-08-27 20:31:22 UTC (rev 34197)
@@ -79,30 +79,6 @@
};
/**
- * Returns the last component of a given path.
- *
- * Examples:
- * c:\foo\bar.txt would return "\bar.txt"
- * c:\foo\bar\ would return "\bar\"
- *
- * @param str Path to obtain the last component from.
- * @return Pointer to the first char of the last component inside str.
- */
-const char *lastPathComponent(const Common::String &str) {
- if(str.empty())
- return "";
-
- const char *start = str.c_str();
- const char *cur = start + str.size() - 2;
-
- while (cur >= start && *cur != '\\') {
- --cur;
- }
-
- return cur + 1;
-}
-
-/**
* Fixes the path by changing all slashes to backslashes.
*
* @param path String with the path to be fixed.
@@ -136,7 +112,7 @@
fixFilePath(_path);
- _displayName = lastPathComponent(_path);
+ _displayName = lastPathComponent(_path, '\\');
TEntry fileAttribs;
TFileName fname;
@@ -257,12 +233,12 @@
if (!_isPseudoRoot && _path.size() > 3) {
p = new SymbianFilesystemNode(false);
const char *start = _path.c_str();
- const char *end = lastPathComponent(_path);
+ const char *end = lastPathComponent(_path, '\\');
p->_path = String(start, end - start);
p->_isValid = true;
p->_isDirectory = true;
- p->_displayName = lastPathComponent(p->_path);
+ p->_displayName = lastPathComponent(p->_path, '\\');
}
else
{
Modified: scummvm/trunk/backends/fs/wii/wii-fs.cpp
===================================================================
--- scummvm/trunk/backends/fs/wii/wii-fs.cpp 2008-08-27 19:29:41 UTC (rev 34196)
+++ scummvm/trunk/backends/fs/wii/wii-fs.cpp 2008-08-27 20:31:22 UTC (rev 34197)
@@ -71,30 +71,6 @@
virtual void setFlags();
};
-/**
- * Returns the last component of a given path.
- *
- * Examples:
- * /foo/bar.txt would return /bar.txt
- * /foo/bar/ would return /bar/
- *
- * @param str String containing the path.
- * @return Pointer to the first char of the last component inside str.
- */
-const char *lastPathComponent(const Common::String &str) {
- if(str.empty())
- return "";
-
- const char *start = str.c_str();
- const char *cur = start + str.size() - 2;
-
- while (cur >= start && *cur != '/') {
- --cur;
- }
-
- return cur + 1;
-}
-
void WiiFilesystemNode::setFlags() {
struct stat st;
@@ -123,7 +99,7 @@
_path = p;
- _displayName = lastPathComponent(_path);
+ _displayName = lastPathComponent(_path, '/');
if (verify)
setFlags();
@@ -187,7 +163,7 @@
return 0;
const char *start = _path.c_str();
- const char *end = lastPathComponent(_path);
+ const char *end = lastPathComponent(_path, '/');
return new WiiFilesystemNode(String(start, end - start), true);
}
Modified: scummvm/trunk/backends/fs/windows/windows-fs.cpp
===================================================================
--- scummvm/trunk/backends/fs/windows/windows-fs.cpp 2008-08-27 19:29:41 UTC (rev 34196)
+++ scummvm/trunk/backends/fs/windows/windows-fs.cpp 2008-08-27 20:31:22 UTC (rev 34197)
@@ -135,30 +135,6 @@
static const TCHAR* toUnicode(const char *str);
};
-/**
- * Returns the last component of a given path.
- *
- * Examples:
- * c:\foo\bar.txt would return "\bar.txt"
- * c:\foo\bar\ would return "\bar\"
- *
- * @param str Path to obtain the last component from.
- * @return Pointer to the first char of the last component inside str.
- */
-const char *lastPathComponent(const Common::String &str) {
- if(str.empty())
- return "";
-
- const char *start = str.c_str();
- const char *cur = start + str.size() - 2;
-
- while (cur >= start && *cur != '\\') {
- --cur;
- }
-
- return cur + 1;
-}
-
void WindowsFilesystemNode::addFile(AbstractFSList &list, ListMode mode, const char *base, WIN32_FIND_DATA* find_data) {
WindowsFilesystemNode entry;
char *asciiName = toAscii(find_data->cFileName);
@@ -232,7 +208,7 @@
_path = p;
}
- _displayName = lastPathComponent(_path);
+ _displayName = lastPathComponent(_path, '\\');
// Check whether it is a directory, and whether the file actually exists
DWORD fileAttribs = GetFileAttributes(toUnicode(_path.c_str()));
@@ -322,13 +298,13 @@
WindowsFilesystemNode *p = new WindowsFilesystemNode();
if (_path.size() > 3) {
const char *start = _path.c_str();
- const char *end = lastPathComponent(_path);
+ const char *end = lastPathComponent(_path, '\\');
p = new WindowsFilesystemNode();
p->_path = String(start, end - start);
p->_isValid = true;
p->_isDirectory = true;
- p->_displayName = lastPathComponent(p->_path);
+ p->_displayName = lastPathComponent(p->_path, '\\');
p->_isPseudoRoot = false;
}
Modified: scummvm/trunk/backends/module.mk
===================================================================
--- scummvm/trunk/backends/module.mk 2008-08-27 19:29:41 UTC (rev 34196)
+++ scummvm/trunk/backends/module.mk 2008-08-27 20:31:22 UTC (rev 34197)
@@ -1,6 +1,7 @@
MODULE := backends
MODULE_OBJS := \
+ fs/abstract-fs.o \
fs/amigaos4/amigaos4-fs-factory.o \
fs/ds/ds-fs-factory.o \
fs/palmos/palmos-fs-factory.o \
Modified: scummvm/trunk/backends/platform/dc/dc-fs.cpp
===================================================================
--- scummvm/trunk/backends/platform/dc/dc-fs.cpp 2008-08-27 19:29:41 UTC (rev 34196)
+++ scummvm/trunk/backends/platform/dc/dc-fs.cpp 2008-08-27 20:31:22 UTC (rev 34197)
@@ -37,13 +37,12 @@
class RoninCDFileNode : public AbstractFilesystemNode {
protected:
String _path;
- static const char *lastPathComponent(const Common::String &str);
public:
RoninCDFileNode(const String &path) : _path(path) {};
virtual bool exists() const { return true; }
- virtual String getName() const { return lastPathComponent(_path); }
+ virtual String getName() const { return lastPathComponent(_path, '/'); }
virtual String getPath() const { return _path; }
virtual bool isDirectory() const { return false; }
virtual bool isReadable() const { return true; }
@@ -75,30 +74,6 @@
virtual bool isReadable() const { return false; }
};
-/**
- * Returns the last component of a given path.
- *
- * Examples:
- * /foo/bar.txt would return /bar.txt
- * /foo/bar/ would return /bar/
- *
- * @param str String containing the path.
- * @return Pointer to the first char of the last component inside str.
- */
-const char *RoninCDFileNode::lastPathComponent(const Common::String &str) {
- if(str.empty())
- return "";
-
- const char *start = str.c_str();
- const char *cur = start + str.size() - 2;
-
- while (cur >= start && *cur != '/') {
- --cur;
- }
-
- return cur + 1;
-}
-
AbstractFilesystemNode *RoninCDFileNode::makeFileNodePath(const Common::String &path) {
assert(path.size() > 0);
@@ -163,7 +138,7 @@
return 0;
const char *start = _path.c_str();
- const char *end = lastPathComponent(_path);
+ const char *end = lastPathComponent(_path, '/');
return new RoninCDDirectoryNode(String(start, end - start));
}
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