home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 January: Mac OS SDK / Dev.CD Jan 97 SDK2.toast / Development Kits (Disc 2) / OpenDoc Development Framework / ODFDev / ODF / Found / FWDebug / SLDebug.cpp < prev    next >
Encoding:
Text File  |  1996-09-17  |  4.5 KB  |  173 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                FWPriDeb.cpp
  4. //    Release Version:    $ ODF 2 $
  5. //
  6. //    Copyright:    (c) 1993-1996 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #include "FWFound.hpp"
  11.  
  12. // Need to include first so that FW_DEBUG is properly defined
  13.  
  14. #ifndef FWPRIDEB_H
  15. #include "FWPriDeb.h"
  16. #endif
  17.  
  18. #ifndef FWPRISTR_H
  19. #include "FWPriStr.h"
  20. #endif
  21.  
  22. #ifndef FWPRIMEM_H
  23. #include "FWPriMem.h"
  24. #endif
  25.  
  26. #if defined(FW_BUILD_MAC) && !defined(__TYPES__)
  27. #include <Types.h>
  28. #endif
  29.  
  30. #if defined(THINK_CPLUS) && !defined(__PASCAL__)
  31. #include <Pascal.h>
  32. #endif
  33.  
  34. #if defined(FW_BUILD_WIN) && !defined(_INC_WINDOWS)
  35. #include <Windows.h>
  36. #endif
  37.  
  38. #ifdef FW_BUILD_MAC
  39. #pragma segment FWDebug
  40. #endif
  41.  
  42.  
  43. //----------------------------------------------------------------------------------------
  44. // privDebugger
  45. //----------------------------------------------------------------------------------------
  46. extern "C" void privDebugger(FW_SDebugConsole* self);
  47.  
  48. void privDebugger(FW_SDebugConsole* self)
  49. {
  50. FW_UNUSED(self);
  51. #if defined(FW_BUILD_WIN)
  52. #ifndef FW_BUILD_DOS
  53.     ::DebugBreak();
  54. #endif
  55.  
  56. #elif defined(FW_BUILD_MAC)
  57.     ::Debugger();
  58. #endif
  59. }
  60.  
  61. #if defined(FW_BUILD_MAC) && !defined(CGLUESUPPORTED)
  62. //----------------------------------------------------------------------------------------
  63. // fwctop
  64. //----------------------------------------------------------------------------------------
  65.  
  66. static void fwctop(char* s)
  67. {
  68.     int len = FW_PrimitiveStringLength(s);
  69.     FW_PrimitiveCopyMemory(s, s+1, len);
  70.     s[0] = len;
  71. }
  72.  
  73. //----------------------------------------------------------------------------------------
  74. // fwptoc
  75. //----------------------------------------------------------------------------------------
  76.  
  77. static void fwptoc(char* s)
  78. {
  79.     int len = s[0];
  80.     FW_PrimitiveCopyMemory(s+1, s, len);
  81.     s[len] = 0;
  82. }
  83.  
  84. //----------------------------------------------------------------------------------------
  85. // debugstr
  86. //----------------------------------------------------------------------------------------
  87. static void debugstr(const char *message)
  88. {
  89.     fwctop((char*) message);
  90.     DebugStr((const unsigned char*) message);
  91.     fwptoc((char*) message);
  92. }
  93. #endif
  94.  
  95. //----------------------------------------------------------------------------------------
  96. // privDebugMessage
  97. //----------------------------------------------------------------------------------------
  98. extern "C" void privDebugMessage(FW_SDebugConsole* self, const char* message);
  99.  
  100.  
  101. void privDebugMessage(FW_SDebugConsole* self, const char* message)
  102. {
  103. #if defined(FW_BUILD_WIN)
  104. #ifndef FW_BUILD_DOS
  105.     char crlf[3] = {0x0D, 0x0A, 0x00};
  106.     ::OutputDebugString(message);
  107.     ::OutputDebugString(crlf);
  108.     ::DebugBreak();
  109.     if (self->fPrivate != 0)
  110.     {
  111.         ::OutputDebugString("Oh, by the way, self->fPrivate should be 0");
  112.         ::OutputDebugString(crlf);
  113.         ::DebugBreak();
  114.     }
  115. #endif
  116.  
  117. #elif defined(FW_BUILD_MAC)
  118.     ::debugstr(message);
  119.     if (self->fPrivate != 0)
  120.         ::debugstr("Oh, by the way, self->fPrivate should be 0");
  121. #endif
  122. }
  123.  
  124.  
  125. //----------------------------------------------------------------------------------------
  126. // If FW_DEBUG is defined, there is a default debug console.  The default console uses 
  127. // whatever debugging packages are available.  If FW_DEBUG is undefined, there is no 
  128. // default debug console.   
  129. //----------------------------------------------------------------------------------------
  130. #ifdef FW_DEBUG
  131. #define FW_DEBUG_CONSOLE &sDebugConsole
  132.  
  133. static FW_SDebugConsole sDebugConsole =
  134. {
  135.     privDebugMessage,
  136.     privDebugMessage,
  137.     privDebugMessage,
  138.     privDebugMessage,
  139.     privDebugger
  140. };
  141. #else
  142. #define FW_DEBUG_CONSOLE {0}
  143. #endif
  144.  
  145.  
  146.  
  147. static FW_SDebugConsole *gDebugConsole = FW_DEBUG_CONSOLE;
  148.  
  149.  
  150. //----------------------------------------------------------------------------------------
  151. // FW_PrivDebugConsole_GetConsole
  152. //----------------------------------------------------------------------------------------
  153.  
  154. FW_EXPORT FW_SDebugConsole* FW_PrivDebugConsole_GetConsole()
  155. {
  156.     // No try block necessary - Do not throw
  157.     return gDebugConsole;
  158. }
  159.  
  160. //----------------------------------------------------------------------------------------
  161. // FW_PrivDebugConsole_SetConsole
  162. //----------------------------------------------------------------------------------------
  163.  
  164. FW_EXPORT FW_SDebugConsole* FW_PrivDebugConsole_SetConsole(FW_SDebugConsole* console)
  165. {
  166.     // No try block necessary - Do not throw
  167.     FW_SDebugConsole* prior = gDebugConsole;
  168.     gDebugConsole = console;
  169.     return prior;
  170. }
  171.  
  172.  
  173.