From 61ea17ff4aba9c23e418c23296e451f80e0b3279 Mon Sep 17 00:00:00 2001 From: Kelvin Sherlock Date: Sat, 16 Feb 2013 13:32:47 -0500 Subject: [PATCH] OS text/binary based on name --- toolbox/os.cpp | 88 ++++++++++++++++++++++++++++++++++++++++++++++++++ toolbox/os.h | 5 +++ 2 files changed, 93 insertions(+) diff --git a/toolbox/os.cpp b/toolbox/os.cpp index d6b8227..541ed3f 100644 --- a/toolbox/os.cpp +++ b/toolbox/os.cpp @@ -8,6 +8,7 @@ #include #include +#include #include #include @@ -16,10 +17,13 @@ #include #include +#include + namespace { using namespace OS; + // should make this public since it's needed by mpw/* uint16_t errno_to_oserr(int xerrno) { switch (xerrno) @@ -47,11 +51,89 @@ namespace { } } + + + std::string extension(const std::string &s) + { + std::string tmp; + int pos; + + pos = s.find_last_of("./:"); + + if (pos == s.npos) return tmp; + if (s[pos++] != '.') return tmp; + if (pos >= s.length()) return tmp; + + tmp = s.substr(pos); + + std::transform(tmp.begin(), tmp.end(), tmp.begin(), + [](char c) { return tolower(c); } + ); + + return tmp; + + } + } namespace OS { + + // known text file extensions + bool IsTextFile(const std::string &s) + { + std::string ext = extension(s); + if (ext.empty()) return false; + + char c = ext[0]; + switch(c) + { + case 'a': + if (ext == "aii") + return true; + break; + + case 'c': + if (ext == "c") + return true; + break; + + case 'p': + if (ext == "pii") + return true; + break; + + case 'r': + if (ext == "rii") + return true; + break; + + } + + return false; + } + + // known binary file extensions + bool IsBinaryFile(const std::string &s) + { + std::string ext = extension(s); + if (ext.empty()) return false; + + char c = ext[0]; + switch(c) + { + case 'o': + if (ext == "obj") + return true; + break; + } + + return false; + } + + + uint16_t Create(uint16_t trap) { uint32_t d0; @@ -202,6 +284,12 @@ namespace OS rv = ::getxattr(sname.c_str(), XATTR_FINDERINFO_NAME, buffer, 32, 0, 0); xerrno = errno; + // override for source files. + if (IsTextFile(sname)) + { + std::memcpy(buffer, "TEXTMPS ", 8); + } + // only 16 bytes copied. std::memcpy(memoryPointer(parm + 32), buffer, 16); diff --git a/toolbox/os.h b/toolbox/os.h index 0b1eb55..45e1931 100644 --- a/toolbox/os.h +++ b/toolbox/os.h @@ -2,6 +2,7 @@ #define __mpw_os_h__ #include +#include namespace OS { @@ -99,6 +100,10 @@ namespace OS }; + bool IsTextFile(const std::string &s); + bool IsBinaryFile(const std::string &s); + + uint16_t Create(uint16_t trap); uint16_t Delete(uint16_t trap);