Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

177 lines
4.2 KiB

  1. /****************************************************************************
  2. DEBUG.H
  3. Owner: cslim
  4. Copyright (c) 1997-1999 Microsoft Corporation
  5. Debug functions
  6. History:
  7. 14-JUL-1999 cslim Copied from IME98 source tree
  8. *****************************************************************************/
  9. #if !defined (_DEBUG_H__INCLUDED_)
  10. #define _DEBUG_H__INCLUDED_
  11. //#include <StdArg.H> // va_list, va_start()
  12. // Debug flag
  13. extern DWORD vdwDebug;
  14. #define DBGID_API 0x00000001 // IME API called
  15. #define DBGID_Key 0x00000002
  16. #define DBGID_Mode 0x00000004
  17. #define DBGID_UI 0x00000008
  18. #define DBGID_UIObj 0x00000010
  19. #define DBGID_Cand 0x00000020
  20. #define DBGID_Conv 0x00000040
  21. #define DBGID_UIWin 0x00000080
  22. #define DBGID_IMECnt 0x00000100
  23. #define DBGID_Tray 0x00000200
  24. #define DBGID_UIMsg 0x00000400
  25. #define DBGID_Mem 0x00000800
  26. #define DBGID_ARRData 0x00001000
  27. #define DBGID_Mouse 0x00002000
  28. #define DBGID_SendMsg 0x00004000
  29. #define DBGID_Automata 0x00008000
  30. #define DBGID_IMENotify 0x00010000
  31. #define DBGID_Hanja 0x00020000
  32. #define DBGID_CompChar 0x00040000
  33. #define DBGID_IMEDATA 0x00080000
  34. #define DBGID_SetComp 0x00100000
  35. #define DBGID_IMEPAD 0x00200000
  36. #define DBGID_Misc 0x01000000
  37. // destination
  38. #define DBGID_OUTCOM 0x00000000
  39. #define DBGID_OUTVIDEO 0x10000000
  40. #define DBGID_OUTFILE 0x20000000
  41. #ifdef DEBUG
  42. // Start of debug code
  43. #define DbgW(a) DebugOutW(a)
  44. VOID InitDebug(VOID);
  45. #define AST(a) _AST(__FILE__, __LINE__, a, #a, fFalse)
  46. #define AST_EX(a) _AST(__FILE__, __LINE__, a, #a, fTrue)
  47. #define DbgAssert AST_EX
  48. inline VOID DebugOut(LPCSTR pSz)
  49. {
  50. static INT DCLine = 0;
  51. //
  52. // out to com
  53. //
  54. OutputDebugStringA(pSz);
  55. //
  56. // out to video
  57. //
  58. if (vdwDebug & DBGID_OUTVIDEO)
  59. {
  60. HDC hDC = GetDC((HWND)0);
  61. static CHAR sz[512];
  62. wsprintfA((LPSTR)sz, "%s||", (CHAR*)pSz);
  63. TextOutA(hDC, 0, DCLine*16, (LPSTR)sz, lstrlenA((LPSTR)sz));
  64. if( DCLine++ > 50 )
  65. {
  66. DCLine = 0;
  67. }
  68. ReleaseDC( (HWND)0, hDC );
  69. }
  70. //
  71. // out to file
  72. //
  73. if (vdwDebug & DBGID_OUTFILE)
  74. {
  75. HANDLE hFile;
  76. DWORD dwWrite;
  77. hFile = CreateFile(TEXT("C:\\IMEDBGKO.TXT"), GENERIC_WRITE, FILE_SHARE_READ, 0, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0 );
  78. SetFilePointer(hFile, 0, NULL, FILE_END);
  79. WriteFile( hFile, pSz, lstrlenA(pSz), &dwWrite, NULL );
  80. WriteFile( hFile, "\r\n", 2, &dwWrite, NULL );
  81. CloseHandle(hFile);
  82. }
  83. }
  84. inline VOID DebugOutW(LPCWSTR pwSz)
  85. {
  86. static CHAR pSz[1280] = {0};
  87. INT cwch = lstrlenW( pwSz );
  88. INT cch = WideCharToMultiByte( 949, 0, (LPWSTR)pwSz, -1, NULL, NULL, NULL, NULL );
  89. WideCharToMultiByte( 949, 0, (LPWSTR)pwSz, cwch, pSz, sizeof(pSz), NULL, NULL );
  90. pSz[cch-1] = 0;
  91. DebugOut( pSz );
  92. }
  93. inline VOID DebugOutT(LPTSTR pwSz)
  94. {
  95. #if !defined (UNICODE)
  96. DebugOut(pwSz);
  97. #else
  98. DebugOutW(pwSz);
  99. #endif
  100. }
  101. inline void cdecl Dbg( DWORD dID, LPCTSTR szFormat, ...)
  102. {
  103. static TCHAR szOutput[512];
  104. va_list valist;
  105. szOutput[0] = 0;
  106. if( vdwDebug & dID )
  107. {
  108. va_start( valist, szFormat );
  109. wvsprintf(szOutput, szFormat, valist);
  110. va_end(valist);
  111. lstrcat(szOutput, TEXT("\r\n"));
  112. DebugOutT(szOutput);
  113. }
  114. return;
  115. }
  116. inline void _AST(LPCSTR szFile, INT iLine, BOOL fAssert, LPCSTR pSz, BOOL fBreak)
  117. {
  118. if( fAssert == fFalse )
  119. {
  120. static CHAR szOutput[512];
  121. wsprintfA(szOutput, "* * * * * A S S E R T I O N F A I L E D * * * * *\r\n%s(%d) : value=%d / %s", szFile, iLine, fTrue, pSz );
  122. lstrcatA(szOutput, "\r\n");
  123. //#if !defined (UNICODE)
  124. DebugOut(szOutput);
  125. //#else
  126. // DebugOutW(szOutput);
  127. //#endif
  128. if( fBreak == fTrue )
  129. {
  130. __try
  131. {
  132. DebugBreak();
  133. }
  134. __except(EXCEPTION_EXECUTE_HANDLER)
  135. {
  136. OutputDebugStringA("DebugBreak");
  137. }
  138. }
  139. }
  140. }
  141. #else
  142. // Start of retail code
  143. // Define Dbg as void(0) will not compile with 64bit compiler
  144. #define Dbg /##/ // Dbg should be appeared as one line. Even brace will cause compile error.
  145. #define DbgW /##/
  146. #define DbgAssert(a)
  147. #define DebugOut(a)
  148. #define DebugOutW(a)
  149. #define DebugOutT(a)
  150. #define AST(a)
  151. #define AST_EX(a)
  152. // End of retail code
  153. #endif // ifndef _DEBUG
  154. #endif // !defined (_DEBUG_H__INCLUDED_)