diff --git a/mpw-shell-parser.cpp b/mpw-shell-parser.cpp index 2523851..bf61e8a 100644 --- a/mpw-shell-parser.cpp +++ b/mpw-shell-parser.cpp @@ -13,7 +13,10 @@ - +namespace ToolBox { + std::string MacToUnix(const std::string path); + std::string UnixToMac(const std::string path); +} template T pop(std::vector &v) { @@ -42,7 +45,9 @@ int open(const std::string &name, int flags) { // dup2 does not copy the O_CLOEXEC flag so it's safe to use. - int fd = ::open(name.c_str(), flags | O_CLOEXEC, 0666); + std::string uname = ToolBox::MacToUnix(name); + + int fd = ::open(uname.c_str(), flags | O_CLOEXEC, 0666); if (fd < 0) { open_error(name); return -1; diff --git a/pathnames.rl b/pathnames.rl index 8220a28..09a25ce 100644 --- a/pathnames.rl +++ b/pathnames.rl @@ -117,11 +117,42 @@ namespace { write data; }%% + %%{ + machine dev; + + main := + '/dev/null'i $eof{ return "/dev/null"; } + | + '/dev/stderr'i $eof{ return "/dev/stderr"; } + | + '/dev/stdout'i $eof{ return "/dev/stdout"; } + ; + write data; + }%% + } namespace ToolBox { + std::string check_dev(std::string &&str) { + + const char *p = str.c_str(); + const char *pe = p + str.length(); + const char *eof = pe; + + int cs; + %%{ + machine dev; + write init; + write exec; + + }%% + + return str; + + } + std::string MacToUnix(const std::string path) { @@ -173,8 +204,7 @@ namespace ToolBox write exec; }%% - - return rv; + return check_dev(std::move(rv)); }