From fe313cea679847db4cd979f7d45cced2f732eb14 Mon Sep 17 00:00:00 2001 From: Max Horn Date: Fri, 15 Nov 2002 17:54:38 +0000 Subject: implemented parent() for POSIX fs code; added .cvsignore files svn-id: r5571 --- backends/fs/morphos/.cvsignore | 1 + backends/fs/posix/posix-fs.cpp | 29 +++++++++++++++++++++++++++-- backends/fs/windows/.cvsignore | 1 + 3 files changed, 29 insertions(+), 2 deletions(-) create mode 100644 backends/fs/morphos/.cvsignore create mode 100644 backends/fs/windows/.cvsignore (limited to 'backends') diff --git a/backends/fs/morphos/.cvsignore b/backends/fs/morphos/.cvsignore new file mode 100644 index 0000000000..39a06683b7 --- /dev/null +++ b/backends/fs/morphos/.cvsignore @@ -0,0 +1 @@ +.deps diff --git a/backends/fs/posix/posix-fs.cpp b/backends/fs/posix/posix-fs.cpp index 65e8c6bd86..0ea131b3f9 100644 --- a/backends/fs/posix/posix-fs.cpp +++ b/backends/fs/posix/posix-fs.cpp @@ -27,6 +27,7 @@ #endif #include #include +#include /* * Implementation of the ScummVM file system API based on POSIX. @@ -119,9 +120,33 @@ FSList *POSIXFilesystemNode::listDir() const { return myList; } +const char *lastPathComponent(const ScummVM::String &str) { + const char *start = str.c_str(); + const char *cur = start + str.size() - 2; + + while (cur > start && *cur != '/') { + --cur; + } + + return cur+1; +} + FilesystemNode *POSIXFilesystemNode::parent() const { - // TODO !!! - return 0; + + POSIXFilesystemNode *p = new POSIXFilesystemNode(); + + // Root node is its own parent. Still we can't just return this + // as the GUI code will call delete on the old node. + if (_path != "/") { + const char *start = _path.c_str(); + const char *end = lastPathComponent(_path); + + p->_path = String(start, end - start); + p->_isValid = true; + p->_isDirectory = true; + p->_displayName = lastPathComponent(p->_path); + } + return p; } #endif // defined(UNIX) diff --git a/backends/fs/windows/.cvsignore b/backends/fs/windows/.cvsignore new file mode 100644 index 0000000000..39a06683b7 --- /dev/null +++ b/backends/fs/windows/.cvsignore @@ -0,0 +1 @@ +.deps -- cgit v1.2.3