mirror of
https://github.com/ksherlock/mpw.git
synced 2024-12-22 00:29:18 +00:00
better pathname conversion
This commit is contained in:
parent
44f1c5a048
commit
57f46bc374
@ -18,6 +18,7 @@
|
||||
#include <cpu/fmem.h>
|
||||
#include <cpu/cpuModule.h>
|
||||
|
||||
#include <toolbox/toolbox.h>
|
||||
#include <toolbox/mm.h>
|
||||
#include <toolbox/os_internal.h>
|
||||
|
||||
@ -116,7 +117,8 @@ namespace MPW
|
||||
|
||||
std::string command = argv[0];
|
||||
|
||||
std::replace(command.begin(), command.end(), '/', ':');
|
||||
command = ToolBox::UnixToMac(command);
|
||||
//std::replace(command.begin(), command.end(), '/', ':');
|
||||
|
||||
argv[0] = basename(argv[0]);
|
||||
|
||||
@ -209,7 +211,8 @@ namespace MPW
|
||||
std::string tmp;
|
||||
std::string root(mpw);
|
||||
|
||||
std::replace(root.begin(), root.end(), '/', ':');
|
||||
root = ToolBox::UnixToMac(root);
|
||||
//std::replace(root.begin(), root.end(), '/', ':');
|
||||
if (root.back() != ':') root.push_back(':');
|
||||
|
||||
tmp = "MPW";
|
||||
|
@ -307,7 +307,7 @@ namespace ToolBox {
|
||||
tmp.assign((char *)memoryPointer(address));
|
||||
}
|
||||
|
||||
if (fname) std::replace(tmp.begin(), tmp.end(), ':', '/');
|
||||
if (fname) tmp = MacToUnix(tmp);
|
||||
|
||||
return tmp;
|
||||
}
|
||||
@ -322,7 +322,7 @@ namespace ToolBox {
|
||||
|
||||
tmp.assign((char *)memoryPointer(address + 1), length);
|
||||
|
||||
if (fname) std::replace(tmp.begin(), tmp.end(), ':', '/');
|
||||
if (fname) tmp = MacToUnix(tmp);
|
||||
|
||||
}
|
||||
|
||||
@ -356,5 +356,84 @@ namespace ToolBox {
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
* MacOS basically does the absolute/relative paths backwards vs unix.
|
||||
*
|
||||
* file -> file
|
||||
* :dir -> dir
|
||||
* :dir:file -> dir/file
|
||||
* volume:file -> /volume/file
|
||||
*/
|
||||
std::string UnixToMac(const std::string &path)
|
||||
{
|
||||
// ./..., //... etc.
|
||||
|
||||
std::string tmp;
|
||||
int sep;
|
||||
|
||||
if (path.empty()) return path;
|
||||
|
||||
sep = path.find_first_of('/');
|
||||
|
||||
if (sep == path.npos)
|
||||
{
|
||||
// no sep -- relative file. treat as-is
|
||||
return path;
|
||||
}
|
||||
if (sep == 0)
|
||||
{
|
||||
// absolute path -- drop the leading /
|
||||
// '/' doesn't make sense.
|
||||
tmp = path.substr(1);
|
||||
}
|
||||
else
|
||||
{
|
||||
// relative path.
|
||||
tmp = '/';
|
||||
tmp.append(path);
|
||||
}
|
||||
|
||||
std::replace(tmp.begin(), tmp.end(), '/', ':');
|
||||
|
||||
return tmp;
|
||||
}
|
||||
|
||||
|
||||
std::string MacToUnix(const std::string &path)
|
||||
{
|
||||
std::string tmp;
|
||||
int sep;
|
||||
int slash;
|
||||
|
||||
if (path.empty()) return path;
|
||||
|
||||
sep = path.find_first_of(':');
|
||||
slash = path.find_first_of('/');
|
||||
|
||||
// if there's a / prior to the :, assume it's a unix prefix.
|
||||
if (sep == path.npos) return path;
|
||||
|
||||
if (slash == path.npos || slash > sep)
|
||||
{
|
||||
if (sep == 0)
|
||||
{
|
||||
// :directory... -> directory
|
||||
tmp = path.substr(1);
|
||||
}
|
||||
else
|
||||
{
|
||||
// volume:path...
|
||||
tmp = '/';
|
||||
tmp.append(path);
|
||||
}
|
||||
}
|
||||
else // assume a unix prefix.
|
||||
{
|
||||
tmp = path;
|
||||
}
|
||||
|
||||
std::replace(tmp.begin(), tmp.end(), ':', '/');
|
||||
|
||||
return tmp;
|
||||
}
|
||||
}
|
@ -29,6 +29,9 @@ namespace ToolBox
|
||||
|
||||
bool WritePString(uint32_t address, const std::string &s);
|
||||
|
||||
|
||||
std::string UnixToMac(const std::string &path);
|
||||
std::string MacToUnix(const std::string &path);
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user