|
From: Paul S. <psn...@us...> - 2004-03-28 22:25:11
|
Update of /cvsroot/whisper2/Whisper/Source/BackEnd/Core/Source/Debugging In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19418/Source/BackEnd/Core/Source/Debugging Modified Files: XLogFile.cpp Log Message: Minor code fixes to build on both Mac and Win32 again; fixes to project files to not cache like mad order things so precompiled headers work again. Index: XLogFile.cpp =================================================================== RCS file: /cvsroot/whisper2/Whisper/Source/BackEnd/Core/Source/Debugging/XLogFile.cpp,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** XLogFile.cpp 15 Aug 2003 10:07:58 -0000 1.6 --- XLogFile.cpp 28 Mar 2004 22:13:15 -0000 1.7 *************** *** 1,296 **** ! /* ! * File: XLogFile.cpp ! * Summary: Dumps information out to a file in the app's folder. ! * Written by: Jesse Jones ! * ! * Copyright © 1999-2001 Jesse Jones. ! * This code is distributed under the zlib/libpng license (see License.txt for details). ! * ! * Change History (most recent first): ! * ! * $Log$ ! * Revision 1.6 2003/08/15 10:07:58 meeroh ! * Macro changes: ! * MAC -> TARGET_OS_MAC ! * WIN -> TARGET_OS_WIN32 ! * TARGET_CARBON -> TARGET_API_MAC_CARBON ! * BIG_ENDIAN -> TARGET_RT_BIG_ENDIAN ! * !BIG_ENDIAN -> TARGET_RT_LITTLE_ENDIAN ! * CODE_WARRIOR -> TARGET_CC_METROWERKS ! * __MWERKS__ -> TARGET_CC_METROWERKS ! * MSVC -> TARGET_CC_MICROSOFT ! * _MSC_VER -> TARGET_CC_MICROSOFT ! * #pragma mark ~ -> #pragma mark - ! * Added #ifdef PRAGMA_MARK ! * ! * Revision 1.5 2003/08/14 06:01:50 meeroh ! * Replaced FSSpecs with CFURLs/FSRefs ! * ! * Revision 1.4 2001/04/17 01:44:21 jesjones ! * Got rid of XInvariantMixin. ! * ! * Revision 1.3 2000/12/10 04:10:29 jesjones ! * Replaced int16_cast, uint32_cast, etc with numeric_cast. ! * ! * Revision 1.2 2000/11/09 12:42:28 jesjones ! * 1) Removed double CRs introduced during the initial checkin. 2) Changed the header comments to make it clearer that Whisper is using the zlib license agreement. 3) Added the Log keyword. ! */ ! ! #include <XWhisperHeader.h> ! #include <XLogFile.h> ! #include <XTranscode.h> ! ! #include <cstdarg> ! #include <cstdio> ! ! #include <XNumbers.h> ! ! namespace Whisper { ! ! using namespace std; ! ! ! // =================================================================================== ! // Internal Functions ! // =================================================================================== ! ! //--------------------------------------------------------------- ! // ! // FSSpecOpen ! // ! //--------------------------------------------------------------- ! #if TARGET_OS_MAC && TARGET_CC_METROWERKS ! #include <FSp_fopen.h> ! static FILE* FSSpecOpen(const OSFSSpec& spec, const char* mode) ! { ! OSFSSpec baseSpec(::CFURLCreateCopyDeletingLastPathComponent(kCFAllocatorDefault, *spec)); ! ! FSRef baseRef; ! if (!::CFURLGetFSRef(*baseSpec, &baseRef)) { ! return nil; ! } ! ! MCoreString path = ::CFURLCopyLastPathComponent(*spec); ! ! HFSUniStr255 hfsPath = ToHFSUniStr(path.c_str()); ! return FSRefParentAndFilename_fopen(&baseRef, &hfsPath, mode); ! } ! #endif ! ! #if PRAGMA_MARK ! #pragma mark - ! #endif ! ! // =================================================================================== ! // class XLogFile ! // =================================================================================== ! ! //--------------------------------------------------------------- ! // ! // XLogFile::~XLogFile ! // ! //--------------------------------------------------------------- ! XLogFile::~XLogFile() ! { ! if (mFile != nil) ! fclose(mFile); ! } ! ! ! //--------------------------------------------------------------- ! // ! // XLogFile::XLogFile ! // ! //--------------------------------------------------------------- ! XLogFile::XLogFile(const char* fileName): ! mFile (nil), ! mFailed (false) ! { ! #if TARGET_OS_MAC ! ProcessSerialNumber psn; ! OSStatus err = ::GetCurrentProcess(&psn); ! ! FSRef appRef; ! if (err == noErr) { ! err = ::GetProcessBundleLocation(&psn, &appRef); ! } ! ! FSRef parentRef; ! if (err == noErr) { ! err = ::FSGetCatalogInfo(&appRef, kFSCatInfoNone, nil, nil, nil, &parentRef); ! } ! ! MCFURL parentSpec (::CFURLCreateFromFSRef (kCFAllocatorDefault, &parentRef)); ! if (parentSpec != nil) { ! mSpec = OSFSSpec(::CFURLCreateWithFileSystemPathRelativeToBase (kCFAllocatorDefault, MCoreString (fileName), ! kCFURLPOSIXPathStyle, false, *parentSpec)); ! } ! ! #elif TARGET_OS_WIN32 ! // Get a path to the exe. ! uint32 succeeded = ::GetModuleFileNameA(GetModuleHandle(nil), mPath, sizeof(mPath)); ! if (succeeded) { ! ! // Find out where the app name starts. ! uint32 pos = ULONG_MAX; ! for (uint32 j = strlen(mPath) - 1; pos == ULONG_MAX && j < ULONG_MAX; --j) { ! if (mPath[j] == '\\') ! pos = j; ! } ! ! // Copy fileName over the app name. ! strcpy(mPath + pos + 1, fileName); ! } ! #endif ! } ! ! ! //--------------------------------------------------------------- ! // ! // XLogFile::Print (const char*, ...) ! // ! //--------------------------------------------------------------- ! void XLogFile::Print(const char* format, ...) ! { ! if (mFile == nil) ! this->DoOpen(); ! ! if (mFile != nil) { ! char mesg[2048]; ! ! va_list args; ! va_start(args, format); ! vsprintf(mesg, format, args); ! va_end(args); ! ! fprintf(mFile, "%s", mesg); ! } ! } ! ! ! //--------------------------------------------------------------- ! // ! // XLogFile::Print (const wchar_t*, ...) ! // ! //--------------------------------------------------------------- ! void XLogFile::Print(const wchar_t* format, ...) ! { ! if (mFile == nil) ! this->DoOpen(); ! ! if (mFile != nil) { ! wchar_t mesg[2048]; ! ! va_list args; ! va_start(args, format); ! vswprintf(mesg, sizeof(mesg)/sizeof(wchar_t), format, args); ! va_end(args); ! ! fprintf(mFile, "%ls", mesg); ! } ! } ! ! ! //--------------------------------------------------------------- ! // ! // XLogFile::Flush ! // ! //--------------------------------------------------------------- ! void XLogFile::Flush() ! { ! if (mFile != nil) ! fflush(mFile); ! } ! ! ! //--------------------------------------------------------------- ! // ! // XLogFile::DoOpen ! // ! //--------------------------------------------------------------- ! void XLogFile::DoOpen() ! { ! if (!mFailed) { // don't attempt to re-open the file if we've already failed ! #if TARGET_OS_MAC ! mFailed = true; // Do not go into an infinite loop if opening a file causes use to print to the log file ! mFile = FSSpecOpen(mSpec, "w"); ! mFailed = false; ! ! if (mFile == nil) ! mFailed = true; ! #elif TARGET_OS_WIN32 ! if (mPath[0] != 0) { ! mFile = fopen(mPath, "w"); ! ! if (mFile == nil) ! mPath[0] = 0; ! #endif ! } ! ! if (mFile != nil) ! this->DoPrintTimeStamp(); ! } ! ! ! //--------------------------------------------------------------- ! // ! // XLogFile::DoPrintTimeStamp ! // ! //--------------------------------------------------------------- ! void XLogFile::DoPrintTimeStamp() ! { ! #if TARGET_OS_MAC ! // Get the current time ! LongDateCvt date; ! date.hl.lHigh = 0; ! ::GetDateTime(&date.hl.lLow); ! ! // Print the date ! Str255 str; ! ::LongDateString(&date.c, abbrevDate, str, nil); ! this->Print("Date: %#s\n", str); ! ! // Print the time ! ::LongTimeString(&date.c, true, str, nil); ! this->Print("Time: %#s\n\n", str); ! ! #elif TARGET_OS_WIN32 ! // Get the current time ! FILETIME date; ! SYSTEMTIME systemTime; ! ::GetLocalTime(&systemTime); ! ! int32 succeeded = ::SystemTimeToFileTime(&systemTime, &date); ! if (!succeeded) goto fail; ! ! // Print the date ! char buffer[2048]; ! ! int32 numChars = ::GetDateFormatA(nil, DATE_LONGDATE, &systemTime, nil, nil, 0); ! if (numChars == 0) goto fail; ! numChars = Min(numChars, (int32) sizeof(buffer)); ! ! succeeded = ::GetDateFormatA(nil, DATE_LONGDATE, &systemTime, nil, buffer, numChars); ! if (!succeeded) goto fail; ! ! this->Print("Date: %*s\n", numChars, buffer); ! ! // Print the time ! numChars = ::GetTimeFormatA(nil, 0UL, &systemTime, nil, nil, 0); ! if (numChars == 0) goto fail; ! numChars = Min(numChars, (int32) sizeof(buffer)); ! ! succeeded = ::GetTimeFormatA(nil, 0UL, &systemTime, nil, buffer, numChars); ! if (!succeeded) goto fail; ! ! this->Print("Time: %*s\n\n", numChars, buffer); ! ! return; ! ! fail: ! this->Print("Couldn't get the timestamp (error: %d)\n", GetLastError()); ! #endif ! } ! ! ! } // namespace Whisper --- 1,4 ---- ! /* * File: XLogFile.cpp * Summary: Dumps information out to a file in the app's folder. * Written by: Jesse Jones * * Copyright © 1999-2001 Jesse Jones. * This code is distributed under the zlib/libpng license (see License.txt for details). * * Change History (most recent first): * * $Log$ ! /* * File: XLogFile.cpp * Summary: Dumps information out to a file in the app's folder. * Written by: Jesse Jones * * Copyright © 1999-2001 Jesse Jones. * This code is distributed under the zlib/libpng license (see License.txt for details). * * Change History (most recent first): * * Revision 1.7 2004/03/28 22:13:15 psnively ! /* * File: XLogFile.cpp * Summary: Dumps information out to a file in the app's folder. * Written by: Jesse Jones * * Copyright © 1999-2001 Jesse Jones. * This code is distributed under the zlib/libpng license (see License.txt for details). * * Change History (most recent first): * * Minor code fixes to build on both Mac and Win32 again; fixes to project files to not cache like mad order things so precompiled headers work again. ! /* * File: XLogFile.cpp * Summary: Dumps information out to a file in the app's folder. * Written by: Jesse Jones * * Copyright © 1999-2001 Jesse Jones. * This code is distributed under the zlib/libpng license (see License.txt for details). * * Change History (most recent first): * * * Revision 1.6 2003/08/15 10:07:58 meeroh * Macro changes: * MAC -> TARGET_OS_MAC * WIN -> TARGET_OS_WIN32 * TARGET_CARBON -> TARGET_API_MAC_CARBON * BIG_ENDIAN -> TARGET_RT_BIG_ENDIAN * !BIG_ENDIAN -> TARGET_RT_LITTLE_ENDIAN * CODE_WARRIOR -> TARGET_CC_METROWERKS * __MWERKS__ -> TARGET_CC_METROWERKS * MSVC -> TARGET_CC_MICROSOFT * _MSC_VER -> TARGET_CC_MICROSOFT * #pragma mark ~ -> #pragma mark - * Added #ifdef PRAGMA_MARK * * Revision 1.5 2003/08/14 06:01:50 meeroh * Replaced FSSpecs with CFURLs/FSRefs * * Revision 1.4 2001/04/17 01:44:21 jesjones * Got rid of XInvariantMixin. * * Revision 1.3 2000/12/10 04:10:29 jesjones * Replaced int16_cast, uint32_cast, etc with numeric_cast. * * Revision 1.2 2000/11/09 12:42:28 jesjones * 1) Removed double CRs introduced during the initial checkin. 2) Changed the header comments to make it clearer that Whisper is using the zlib license agreement. 3) Added the Log keyword. */ #include <XWhisperHeader.h> #include <XLogFile.h> #include <XTranscode.h> #include <cstdarg> #include <cstdio> #include <XNumbers.h> namespace Whisper { using namespace std; // =================================================================================== // Internal Functions // =================================================================================== //--------------------------------------------------------------- // // FSSpecOpen // //--------------------------------------------------------------- #if TARGET_OS_MAC && TARGET_CC_METROWERKS #include <FSp_fopen.h> static FILE* FSSpecOpen(const OSFSSpec& spec, const char* mode) { OSFSSpec baseSpec(::CFURLCreateCopyDeletingLastPathComponent(kCFAllocatorDefault, *spec)); FSRef baseRef; if (!::CFURLGetFSRef(*baseSpec, &baseRef)) { return nil; } MCoreString path = ::CFURLCopyLastPathComponent(*spec); HFSUniStr255 hfsPath = ToHFSUniStr(path.c_str()); return FSRefParentAndFilename_fopen(&baseRef, &hfsPath, mode); } #endif #if PRAGMA_MARK #pragma mark - #endif // =================================================================================== // class XLogFile // =================================================================================== //--------------------------------------------------------------- // // XLogFile::~XLogFile // //--------------------------------------------------------------- XLogFile::~XLogFile() { if (mFile != nil) fclose(mFile); } //--------------------------------------------------------------- // // XLogFile::XLogFile // //--------------------------------------------------------------- XLogFile::XLogFile(const char* fileName): mFile (nil), mFailed (false) { #if TARGET_OS_MAC ProcessSerialNumber psn; OSStatus err = ::GetCurrentProcess(&psn); FSRef appRef; if (err == noErr) { err = ::GetProcessBundleLocation(&psn, &appRef); } FSRef parentRef; if (err == noErr) { err = ::FSGetCatalogInfo(&appRef, kFSCatInfoNone, nil, nil, nil, &parentRef); } MCFURL parentSpec (::CFURLCreateFromFSRef (kCFAllocatorDefault, &parentRef)); if (parentSpec != nil) { mSpec = OSFSSpec(::CFURLCreateWithFileSystemPathRelativeToBase (kCFAllocatorDefault, MCoreString (fileName), kCFURLPOSIXPathStyle, false, *parentSpec)); } #elif TARGET_OS_WIN32 // Get a path to the exe. uint32 succeeded = ::GetModuleFileNameA(GetModuleHandle(nil), mPath, sizeof(mPath)); if (succeeded) { // Find out where the app name starts. uint32 pos = ULONG_MAX; for (uint32 j = strlen(mPath) - 1; pos == ULONG_MAX && j < ULONG_MAX; --j) { if (mPath[j] == '\\') pos = j; } // Copy fileName over the app name. strcpy(mPath + pos + 1, fileName); } #endif } //--------------------------------------------------------------- // // XLogFile::Print (const char*, ...) // //--------------------------------------------------------------- void XLogFile::Print(const char* format, ...) { if (mFile == nil) this->DoOpen(); if (mFile != nil) { char mesg[2048]; va_list args; va_start(args, format); vsprintf(mesg, format, args); va_end(args); fprintf(mFile, "%s", mesg); } } //--------------------------------------------------------------- // // XLogFile::Print (const wchar_t*, ...) // //--------------------------------------------------------------- void XLogFile::Print(const wchar_t* format, ...) { if (mFile == nil) this->DoOpen(); if (mFile != nil) { wchar_t mesg[2048]; va_list args; va_start(args, format); vswprintf(mesg, sizeof(mesg)/sizeof(wchar_t), format, args); va_end(args); fprintf(mFile, "%ls", mesg); } } //--------------------------------------------------------------- // // XLogFile::Flush // //--------------------------------------------------------------- void XLogFile::Flush() { if (mFile != nil) fflush(mFile); } //--------------------------------------------------------------- // // XLogFile::DoOpen // //--------------------------------------------------------------- void XLogFile::DoOpen() { if (!mFailed) { // don't attempt to re-open the file if we've already failed #if TARGET_OS_MAC mFailed = true; // Do not go into an infinite loop if opening a file causes use to print to the log file mFile = FSSpecOpen(mSpec, "w"); mFailed = false; if (mFile == nil) mFailed = true; #elif TARGET_OS_WIN32 if (mPath[0] != 0) { mFile = fopen(mPath, "w"); if (mFile == nil) mPath[0] = 0; } #endif } if (mFile != nil) this->DoPrintTimeStamp(); } //--------------------------------------------------------------- // // XLogFile::DoPrintTimeStamp // //--------------------------------------------------------------- void XLogFile::DoPrintTimeStamp() { #if TARGET_OS_MAC // Get the current time LongDateCvt date; date.hl.lHigh = 0; ::GetDateTime(&date.hl.lLow); // Print the date Str255 str; ::LongDateString(&date.c, abbrevDate, str, nil); this->Print("Date: %#s\n", str); // Print the time ::LongTimeString(&date.c, true, str, nil); this->Print("Time: %#s\n\n", str); #elif TARGET_OS_WIN32 // Get the current time FILETIME date; SYSTEMTIME systemTime; ::GetLocalTime(&systemTime); int32 succeeded = ::SystemTimeToFileTime(&systemTime, &date); if (!succeeded) goto fail; // Print the date char buffer[2048]; int32 numChars = ::GetDateFormatA(nil, DATE_LONGDATE, &systemTime, nil, nil, 0); if (numChars == 0) goto fail; numChars = Min(numChars, (int32) sizeof(buffer)); succeeded = ::GetDateFormatA(nil, DATE_LONGDATE, &systemTime, nil, buffer, numChars); if (!succeeded) goto fail; this->Print("Date: %*s\n", numChars, buffer); // Print the time numChars = ::GetTimeFormatA(nil, 0UL, &systemTime, nil, nil, 0); if (numChars == 0) goto fail; numChars = Min(numChars, (int32) sizeof(buffer)); succeeded = ::GetTimeFormatA(nil, 0UL, &systemTime, nil, buffer, numChars); if (!succeeded) goto fail; this->Print("Time: %*s\n\n", numChars, buffer); return; fail: this->Print("Couldn't get the timestamp (error: %d)\n", GetLastError()); #endif } } // namespace Whisper \ No newline at end of file |