RISCOS: Move the path conversion functions into a separate file
This commit is contained in:
parent
bcef809e61
commit
8c15b41dd7
6 changed files with 129 additions and 64 deletions
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -35,6 +35,7 @@ endif
|
|||
ifdef RISCOS
|
||||
MODULE_OBJS += \
|
||||
riscos/riscos-main.o \
|
||||
riscos/riscos-utils.o \
|
||||
riscos/riscos.o
|
||||
endif
|
||||
|
||||
|
|
70
backends/platform/sdl/riscos/riscos-utils.cpp
Normal file
70
backends/platform/sdl/riscos/riscos-utils.cpp
Normal file
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
49
backends/platform/sdl/riscos/riscos-utils.h
Normal file
49
backends/platform/sdl/riscos/riscos-utils.h
Normal file
|
@ -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
|
Loading…
Add table
Add a link
Reference in a new issue