From 698cf056afa78a3f7ca4a90389c4bbc77ba6f324 Mon Sep 17 00:00:00 2001 From: "ducarroz%netscape.com" Date: Fri, 2 Apr 1999 01:00:37 +0000 Subject: [PATCH] Part of Messenger Mac landing git-svn-id: svn://10.0.0.236/trunk@25975 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/db/mork/src/morkConfig.cpp | 3 +- mozilla/db/mork/src/morkConfig.h | 2 - mozilla/mailnews/db/mork/src/morkConfig.cpp | 3 +- mozilla/mailnews/db/mork/src/morkConfig.h | 2 - .../mailnews/db/msgdb/public/nsMsgDatabase.h | 5 +- .../mailnews/db/msgdb/src/nsMailDatabase.cpp | 12 ++- .../mailnews/db/msgdb/src/nsMsgDatabase.cpp | 79 ++++++++++++++++++- 7 files changed, 93 insertions(+), 13 deletions(-) diff --git a/mozilla/db/mork/src/morkConfig.cpp b/mozilla/db/mork/src/morkConfig.cpp index d62be2b7a69..a2e6a83c63b 100644 --- a/mozilla/db/mork/src/morkConfig.cpp +++ b/mozilla/db/mork/src/morkConfig.cpp @@ -34,12 +34,13 @@ #ifdef MORK_OBSOLETE #include +#include "plstr.h" static void // copied almost verbatim from the IronDoc debugger sources: mork_mac_break_string(register const char* inMessage) /*i*/ { Str255 pascalStr; // to hold Pascal string version of inMessage - mork_u4 length = XP_STRLEN(inMessage); + mork_u4 length = PL_strlen(inMessage); // if longer than maximum 255 bytes, just copy 255 bytes worth pascalStr[ 0 ] = (length > 255)? 255 : length; diff --git a/mozilla/db/mork/src/morkConfig.h b/mozilla/db/mork/src/morkConfig.h index cfd3356ccc2..45ba918f505 100644 --- a/mozilla/db/mork/src/morkConfig.h +++ b/mozilla/db/mork/src/morkConfig.h @@ -31,7 +31,6 @@ // { %%%%% begin platform defs peculiar to Mork %%%%% #ifdef XP_MAC -#define MORK_OBSOLETE 1 #define MORK_MAC 1 #endif @@ -74,7 +73,6 @@ #ifdef MORK_OBSOLETE #include "xp_file.h" #include "ctype.h" - #define MORK_ISPRINT(c) isprint(c) #define MORK_FILETELL(file) XP_FileTell(file) diff --git a/mozilla/mailnews/db/mork/src/morkConfig.cpp b/mozilla/mailnews/db/mork/src/morkConfig.cpp index d62be2b7a69..a2e6a83c63b 100644 --- a/mozilla/mailnews/db/mork/src/morkConfig.cpp +++ b/mozilla/mailnews/db/mork/src/morkConfig.cpp @@ -34,12 +34,13 @@ #ifdef MORK_OBSOLETE #include +#include "plstr.h" static void // copied almost verbatim from the IronDoc debugger sources: mork_mac_break_string(register const char* inMessage) /*i*/ { Str255 pascalStr; // to hold Pascal string version of inMessage - mork_u4 length = XP_STRLEN(inMessage); + mork_u4 length = PL_strlen(inMessage); // if longer than maximum 255 bytes, just copy 255 bytes worth pascalStr[ 0 ] = (length > 255)? 255 : length; diff --git a/mozilla/mailnews/db/mork/src/morkConfig.h b/mozilla/mailnews/db/mork/src/morkConfig.h index cfd3356ccc2..45ba918f505 100644 --- a/mozilla/mailnews/db/mork/src/morkConfig.h +++ b/mozilla/mailnews/db/mork/src/morkConfig.h @@ -31,7 +31,6 @@ // { %%%%% begin platform defs peculiar to Mork %%%%% #ifdef XP_MAC -#define MORK_OBSOLETE 1 #define MORK_MAC 1 #endif @@ -74,7 +73,6 @@ #ifdef MORK_OBSOLETE #include "xp_file.h" #include "ctype.h" - #define MORK_ISPRINT(c) isprint(c) #define MORK_FILETELL(file) XP_FileTell(file) diff --git a/mozilla/mailnews/db/msgdb/public/nsMsgDatabase.h b/mozilla/mailnews/db/msgdb/public/nsMsgDatabase.h index c9330967525..5da9139be78 100644 --- a/mozilla/mailnews/db/msgdb/public/nsMsgDatabase.h +++ b/mozilla/mailnews/db/msgdb/public/nsMsgDatabase.h @@ -236,9 +236,12 @@ protected: static int FindInCache(nsMsgDatabase* pMessageDB); PRBool MatchDbName(nsFileSpec &dbName); // returns TRUE if they match -#ifdef XP_PC // this should go away when we can provide our own file stream to MDB/Mork +#if defined(XP_PC) || defined(XP_MAC) // this should go away when we can provide our own file stream to MDB/Mork static void UnixToNative(char*& ioPath); #endif +#if defined(XP_MAC) + static void NativeToUnix(char*& ioPath); +#endif // Flag handling routines virtual nsresult SetKeyFlag(nsMsgKey key, PRBool set, PRInt32 flag, diff --git a/mozilla/mailnews/db/msgdb/src/nsMailDatabase.cpp b/mozilla/mailnews/db/msgdb/src/nsMailDatabase.cpp index 625a370f4ba..352a81ae28e 100644 --- a/mozilla/mailnews/db/msgdb/src/nsMailDatabase.cpp +++ b/mozilla/mailnews/db/msgdb/src/nsMailDatabase.cpp @@ -74,7 +74,7 @@ nsMailDatabase::~nsMailDatabase() char *nativeFolderName = nsCRT::strdup((const char *) folderName); -#ifdef XP_PC +#if defined(XP_PC) || defined(XP_MAC) UnixToNative(nativeFolderName); #endif stat (nativeFolderName, &st); @@ -221,6 +221,7 @@ void nsMailDatabase::UpdateFolderFlag(nsIMessage *mailHdr, PRBool bSet, nsIOFileStream *fileStream = (m_folderStream) ? m_folderStream : *ppFileStream; //#ifdef GET_FILE_STUFF_TOGETHER #ifdef XP_MAC +/* ducarroz: Do we still need this ?? // This is a horrible hack and we should make sure we don't need it anymore. // It has to do with multiple people having the same file open, I believe, but the // mac file system only has one handle, and they compete for the file position. @@ -231,6 +232,7 @@ void nsMailDatabase::UpdateFolderFlag(nsIMessage *mailHdr, PRBool bSet, fid = gIncorporateFID; savedPosition = ftell(gIncorporateFID); // so we can restore it. } +*/ #endif // XP_MAC PRUint32 offset; (void)mailHdr->GetStatusOffset(&offset); @@ -313,9 +315,11 @@ void nsMailDatabase::UpdateFolderFlag(nsIMessage *mailHdr, PRBool bSet, SetReparse(TRUE); } #ifdef XP_MAC +/* ducarroz: Do we still need this ?? // Restore the file position if (savedPosition >= 0) XP_FileSeek(fid, savedPosition, SEEK_SET); +*/ #endif } else @@ -327,7 +331,7 @@ void nsMailDatabase::UpdateFolderFlag(nsIMessage *mailHdr, PRBool bSet, } //#endif // GET_FILE_STUFF_TOGETHER #ifdef XP_MAC - if (!m_folderStream && fid != gIncorporateFID) + if (!m_folderStream /*&& fid != gIncorporateFID*/) /* ducarroz: Do we still need this ?? */ #else if (!m_folderStream) #endif @@ -339,7 +343,7 @@ void nsMailDatabase::UpdateFolderFlag(nsIMessage *mailHdr, PRBool bSet, nsresult ret = NS_OK; struct stat st; char *nativeFileName = nsCRT::strdup(m_folderName); -#ifdef XP_PC +#if defined(XP_PC) || defined(XP_MAC) UnixToNative(nativeFileName); #endif @@ -435,7 +439,7 @@ nsresult nsMailDatabase::SetFolderInfoValid(nsFileSpec &folderName, int num, int nsresult err; char *nativeFileName = nsCRT::strdup(folderName); -#ifdef XP_PC +#if defined(XP_PC) || defined(XP_MAC) UnixToNative(nativeFileName); #endif diff --git a/mozilla/mailnews/db/msgdb/src/nsMsgDatabase.cpp b/mozilla/mailnews/db/msgdb/src/nsMsgDatabase.cpp index 0e8f42804e8..3df87a61fef 100644 --- a/mozilla/mailnews/db/msgdb/src/nsMsgDatabase.cpp +++ b/mozilla/mailnews/db/msgdb/src/nsMsgDatabase.cpp @@ -36,7 +36,12 @@ #include "nsILocale.h" #include "nsLocaleCID.h" #include "nsILocaleFactory.h" + +#if defined(XP_MAC) && defined(CompareString) + #undef CompareString +#endif #include "nsICollation.h" + #include "nsCollationCID.h" #include "nsIPref.h" @@ -436,8 +441,71 @@ void nsMsgDatabase::UnixToNative(char*& ioPath) *cp = *(cp + 1); } } - #endif /* XP_PC */ + +#ifdef XP_MAC +// this code is stolen from nsFileSpecMac. Since MDB requires a native path, for +// the time being, we'll just take the Unix/Canonical form and munge it +void nsMsgDatabase::UnixToNative(char*& ioPath) +// This just does string manipulation. It doesn't check reality, or canonify, or +// anything +//---------------------------------------------------------------------------------------- +{ + // Relying on the fact that the unix path is always longer than the mac path: + size_t len = strlen(ioPath); + char* result = new char[len + 2]; // ... but allow for the initial colon in a partial name + if (result) + { + char* dst = result; + const char* src = ioPath; + if (*src == '/') // * full path + src++; + else if (strchr(src, '/')) // * partial path, and not just a leaf name + *dst++ = ':'; + strcpy(dst, src); + + while ( *dst != 0) + { + if (*dst == '/') + *dst++ = ':'; + else + *dst++; + } + PR_Free(ioPath); + ioPath = result; + } +} + +void nsMsgDatabase::NativeToUnix(char*& ioPath) +// This just does string manipulation. It doesn't check reality, or canonify, or +// anything +//---------------------------------------------------------------------------------------- +{ + size_t len = strlen(ioPath); + char* result = new char[len + 2]; // ... but allow for the initial colon in a partial name + if (result) + { + char* dst = result; + const char* src = ioPath; + if (*src == ':') // * partial path, and not just a leaf name + src++; + else if (strchr(src, ':')) // * full path + *dst++ = '/'; + strcpy(dst, src); + + while ( *dst != 0) + { + if (*dst == ':') + *dst++ = '/'; + else + *dst++; + } + PR_Free(ioPath); + ioPath = result; + } +} +#endif /* XP_MAC */ + // Open the MDB database synchronously. If successful, this routine // will set up the m_mdbStore and m_mdbEnv of the database object // so other database calls can work. @@ -454,8 +522,15 @@ NS_IMETHODIMP nsMsgDatabase::OpenMDB(const char *dbName, PRBool create) struct stat st; char *nativeFileName = nsCRT::strdup(dbName); +#if defined(XP_MAC) + char * unixPath = nsCRT::strdup(dbName); + NativeToUnix(unixPath); + m_dbName = nsCRT::strdup(unixPath); + delete [] unixPath; +#else m_dbName = nsCRT::strdup(dbName); -#ifdef XP_PC +#endif +#if defined(XP_PC) || defined(XP_MAC) UnixToNative(nativeFileName); #endif if (stat(nativeFileName, &st))