aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCameron Cawley2019-03-28 22:35:13 +0000
committerCameron Cawley2019-04-15 16:24:51 +0100
commit8c15b41dd73e2f44e59b4918bdaaa522d22c5526 (patch)
treed40c84cd5fc057e7607c8298be6e893b36e55340
parentbcef809e612177c2bcb7ca3f8682ea96d38c4cdc (diff)
downloadscummvm-rg350-8c15b41dd73e2f44e59b4918bdaaa522d22c5526.tar.gz
scummvm-rg350-8c15b41dd73e2f44e59b4918bdaaa522d22c5526.tar.bz2
scummvm-rg350-8c15b41dd73e2f44e59b4918bdaaa522d22c5526.zip
RISCOS: Move the path conversion functions into a separate file
-rw-r--r--backends/fs/riscos/riscos-fs.cpp52
-rw-r--r--backends/fs/riscos/riscos-fs.h18
-rw-r--r--backends/module.mk3
-rw-r--r--backends/platform/sdl/module.mk1
-rw-r--r--backends/platform/sdl/riscos/riscos-utils.cpp70
-rw-r--r--backends/platform/sdl/riscos/riscos-utils.h49
6 files changed, 129 insertions, 64 deletions
diff --git a/backends/fs/riscos/riscos-fs.cpp b/backends/fs/riscos/riscos-fs.cpp
index 7ee20e7c0a..6f195691a0 100644
--- a/backends/fs/riscos/riscos-fs.cpp
+++ b/backends/fs/riscos/riscos-fs.cpp
@@ -26,6 +26,7 @@
#define FORBIDDEN_SYMBOL_EXCEPTION_unistd_h
#define FORBIDDEN_SYMBOL_EXCEPTION_mkdir
+#include "backends/platform/sdl/riscos/riscos-utils.h"
#include "backends/fs/riscos/riscos-fs.h"
#include "backends/fs/stdiostream.h"
#include "common/algorithm.h"
@@ -57,7 +58,7 @@ RISCOSFilesystemNode::RISCOSFilesystemNode(const Common::String &p) {
_isDirectory = true;
_isValid = true;
} else {
- int type = _swi(OS_File, _INR(0,1)|_RETURN(0), 20, toRISCOS(_path).c_str());
+ int type = _swi(OS_File, _INR(0,1)|_RETURN(0), 20, RISCOS_Utils::toRISCOS(_path).c_str());
if (type == 0) {
_isDirectory = false;
_isValid = false;
@@ -71,45 +72,6 @@ RISCOSFilesystemNode::RISCOSFilesystemNode(const Common::String &p) {
}
}
-Common::String RISCOSFilesystemNode::toRISCOS(Common::String &path) {
- char start[PATH_MAX];
- char *end = __riscosify_std(path.c_str(), 0, start, PATH_MAX, 0);
- return Common::String(start, end);
-}
-
-Common::String RISCOSFilesystemNode::toUnix(Common::String &path) {
- Common::String out = Common::String(path);
- uint32 start = 0;
- if (out.contains("$")) {
- char *x = strstr(out.c_str(), "$");
- start = x ? x - out.c_str() : -1;
- } else if (out.contains(":")) {
- char *x = strstr(out.c_str(), ":");
- start = x ? x - out.c_str() : -1;
- }
-
- for (uint32 ptr = start; ptr < out.size(); ptr += 1) {
- switch (out.c_str()[ptr]) {
- case '.':
- out.setChar('/', ptr);
- break;
- case '/':
- out.setChar('.', ptr);
- break;
- case '\xA0':
- out.setChar(' ', ptr);
- break;
- default:
- break;
- }
- }
-
- if (out.contains("$") || out.contains(":"))
- out = "/" + out;
-
- return out;
-}
-
AbstractFSNode *RISCOSFilesystemNode::getChild(const Common::String &n) const {
assert(!_path.empty());
assert(_isDirectory);
@@ -169,7 +131,7 @@ bool RISCOSFilesystemNode::getChildren(AbstractFSList &myList, ListMode mode, bo
Common::String dir = _path;
while (count != -1) {
- _swix(OS_GBPB, _INR(0,5)|_OUTR(3,4), 9, toRISCOS(dir).c_str(), file, 1, count, sizeof(file), &read, &count);
+ _swix(OS_GBPB, _INR(0,5)|_OUTR(3,4), 9, RISCOS_Utils::toRISCOS(dir).c_str(), file, 1, count, sizeof(file), &read, &count);
if (count == -1)
continue;
@@ -177,12 +139,12 @@ bool RISCOSFilesystemNode::getChildren(AbstractFSList &myList, ListMode mode, bo
// Start with a clone of this node, with the correct path set
RISCOSFilesystemNode entry(*this);
entry._displayName = file;
- entry._displayName = toUnix(entry._displayName);
+ entry._displayName = RISCOS_Utils::toUnix(entry._displayName);
if (_path.lastChar() != '/')
entry._path += '/';
entry._path += entry._displayName;
- int type = _swi(OS_File, _INR(0,1)|_RETURN(0), 20, toRISCOS(entry._path).c_str());
+ int type = _swi(OS_File, _INR(0,1)|_RETURN(0), 20, RISCOS_Utils::toRISCOS(entry._path).c_str());
if (type == 0) {
continue;
} else if (type == 2) {
@@ -240,7 +202,7 @@ bool RISCOSFilesystemNode::create(bool isDirectoryFlag) {
bool success;
if (isDirectoryFlag) {
- success = _swix(OS_File, _INR(0,1), 8, toRISCOS(_path).c_str()) == NULL;
+ success = _swix(OS_File, _INR(0,1), 8, RISCOS_Utils::toRISCOS(_path).c_str()) == NULL;
} else {
int fd = open(_path.c_str(), O_WRONLY | O_CREAT | O_TRUNC, 0755);
success = fd >= 0;
@@ -252,7 +214,7 @@ bool RISCOSFilesystemNode::create(bool isDirectoryFlag) {
if (success) {
if (exists()) {
- _isDirectory = _swi(OS_File, _INR(0,1)|_RETURN(0), 20, toRISCOS(_path).c_str()) == 2;
+ _isDirectory = _swi(OS_File, _INR(0,1)|_RETURN(0), 20, RISCOS_Utils::toRISCOS(_path).c_str()) == 2;
if (_isDirectory != isDirectoryFlag) warning("failed to create %s: got %s", isDirectoryFlag ? "directory" : "file", _isDirectory ? "directory" : "file");
return _isDirectory == isDirectoryFlag;
}
diff --git a/backends/fs/riscos/riscos-fs.h b/backends/fs/riscos/riscos-fs.h
index b02f30bce7..99fa1d59be 100644
--- a/backends/fs/riscos/riscos-fs.h
+++ b/backends/fs/riscos/riscos-fs.h
@@ -68,24 +68,6 @@ public:
virtual Common::SeekableReadStream *createReadStream();
virtual Common::WriteStream *createWriteStream();
virtual bool create(bool isDirectoryFlag);
-
-private:
- /**
- * Converts a Unix style path to a RISC OS style path.
- *
- * @param str Unix style path to convert.
- * @return RISC OS style path.
- */
- static Common::String toRISCOS(Common::String &path);
-
- /**
- * Converts a RISC OS style path to a Unix style path.
- *
- * @param str RISC OS style path to convert.
- * @return Unix style path.
- */
- static Common::String toUnix(Common::String &path);
-
};
namespace Riscos {
diff --git a/backends/module.mk b/backends/module.mk
index 4d2bdc1c08..5a49d55e3d 100644
--- a/backends/module.mk
+++ b/backends/module.mk
@@ -215,7 +215,8 @@ endif
ifdef RISCOS
MODULE_OBJS += \
fs/riscos/riscos-fs.o \
- fs/riscos/riscos-fs-factory.o
+ fs/riscos/riscos-fs-factory.o \
+ platform/sdl/riscos/riscos-utils.o
endif
ifdef PLAYSTATION3
diff --git a/backends/platform/sdl/module.mk b/backends/platform/sdl/module.mk
index c5036be727..e9533ab711 100644
--- a/backends/platform/sdl/module.mk
+++ b/backends/platform/sdl/module.mk
@@ -35,6 +35,7 @@ endif
ifdef RISCOS
MODULE_OBJS += \
riscos/riscos-main.o \
+ riscos/riscos-utils.o \
riscos/riscos.o
endif
diff --git a/backends/platform/sdl/riscos/riscos-utils.cpp b/backends/platform/sdl/riscos/riscos-utils.cpp
new file mode 100644
index 0000000000..b26081d329
--- /dev/null
+++ b/backends/platform/sdl/riscos/riscos-utils.cpp
@@ -0,0 +1,70 @@
+/* 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.
+ *
+ */
+
+#include "common/scummsys.h"
+#include "backends/platform/sdl/riscos/riscos-utils.h"
+
+#include <unixlib/local.h>
+#include <limits.h>
+
+namespace RISCOS_Utils {
+
+Common::String toRISCOS(Common::String path) {
+ char start[PATH_MAX];
+ char *end = __riscosify_std(path.c_str(), 0, start, PATH_MAX, 0);
+ return Common::String(start, end);
+}
+
+Common::String toUnix(Common::String path) {
+ Common::String out = Common::String(path);
+ uint32 start = 0;
+ if (out.contains("$")) {
+ char *x = strstr(out.c_str(), "$");
+ start = x ? x - out.c_str() : -1;
+ } else if (out.contains(":")) {
+ char *x = strstr(out.c_str(), ":");
+ start = x ? x - out.c_str() : -1;
+ }
+
+ for (uint32 ptr = start; ptr < out.size(); ptr += 1) {
+ switch (out.c_str()[ptr]) {
+ case '.':
+ out.setChar('/', ptr);
+ break;
+ case '/':
+ out.setChar('.', ptr);
+ break;
+ case '\xA0':
+ out.setChar(' ', ptr);
+ break;
+ default:
+ break;
+ }
+ }
+
+ if (out.contains("$") || out.contains(":"))
+ out = "/" + out;
+
+ return out;
+}
+
+}
diff --git a/backends/platform/sdl/riscos/riscos-utils.h b/backends/platform/sdl/riscos/riscos-utils.h
new file mode 100644
index 0000000000..5d8c1fd6ef
--- /dev/null
+++ b/backends/platform/sdl/riscos/riscos-utils.h
@@ -0,0 +1,49 @@
+/* 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.
+ *
+ */
+
+#ifndef PLATFORM_SDL_RISCOS_UTILS_H
+#define PLATFORM_SDL_RISCOS_UTILS_H
+
+#include "common/str.h"
+
+// Helper functions
+namespace RISCOS_Utils {
+
+/**
+ * Converts a Unix style path to a RISC OS style path.
+ *
+ * @param str Unix style path to convert.
+ * @return RISC OS style path.
+ */
+Common::String toRISCOS(Common::String path);
+
+/**
+ * Converts a RISC OS style path to a Unix style path.
+ *
+ * @param str RISC OS style path to convert.
+ * @return Unix style path.
+ */
+Common::String toUnix(Common::String path);
+
+}
+
+#endif