Source code of Windows XP (NT5)
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.

239 lines
4.6 KiB

  1. //==========================================================================;
  2. //
  3. // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
  4. // ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED
  5. // TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR
  6. // A PARTICULAR PURPOSE.
  7. //
  8. // Copyright (C) 1993 - 1995 Microsoft Corporation. All Rights Reserved.
  9. //
  10. //--------------------------------------------------------------------------;
  11. //
  12. // debug.c
  13. //
  14. // Description:
  15. // This file contains code yanked from several places to provide debug
  16. // support that works in win 16 and win 32.
  17. //
  18. // History:
  19. // 11/23/92
  20. //
  21. //==========================================================================;
  22. #ifdef DEBUG
  23. #include <windows.h>
  24. #include <windowsx.h>
  25. #include <stdarg.h>
  26. #include "debug.h"
  27. //
  28. // since we don't UNICODE our debugging messages, use the ASCII entry
  29. // points regardless of how we are compiled.
  30. //
  31. #ifdef WIN32
  32. #include <wchar.h>
  33. #else
  34. #define lstrcatA lstrcat
  35. #define lstrlenA lstrlen
  36. #define wvsprintfA wvsprintf
  37. #define GetProfileIntA GetProfileInt
  38. #define OutputDebugStringA OutputDebugString
  39. #endif
  40. //
  41. //
  42. //
  43. BOOL __gfDbgEnabled = TRUE; // master enable
  44. UINT __guDbgLevel = 0; // current debug level
  45. //--------------------------------------------------------------------------;
  46. //
  47. // void DbgVPrintF(LPSTR szFmt, LPSTR va)
  48. //
  49. // Description:
  50. //
  51. //
  52. // Arguments:
  53. //
  54. // Return (void):
  55. //
  56. //
  57. // History:
  58. // 11/28/92
  59. //
  60. //--------------------------------------------------------------------------;
  61. void FAR CDECL DbgVPrintF(LPSTR szFmt, LPSTR va)
  62. {
  63. char ach[DEBUG_MAX_LINE_LEN];
  64. BOOL fDebugBreak = FALSE;
  65. BOOL fPrefix = TRUE;
  66. BOOL fCRLF = TRUE;
  67. ach[0] = '\0';
  68. for (;;)
  69. {
  70. switch(*szFmt)
  71. {
  72. case '!':
  73. fDebugBreak = TRUE;
  74. szFmt++;
  75. continue;
  76. case '`':
  77. fPrefix = FALSE;
  78. szFmt++;
  79. continue;
  80. case '~':
  81. fCRLF = FALSE;
  82. szFmt++;
  83. continue;
  84. }
  85. break;
  86. }
  87. if (fDebugBreak)
  88. {
  89. ach[0] = '\007';
  90. ach[1] = '\0';
  91. }
  92. if (fPrefix)
  93. lstrcatA(ach, DEBUG_MODULE_NAME ": ");
  94. wvsprintfA(ach + lstrlenA(ach), szFmt, va);
  95. if (fCRLF)
  96. lstrcatA(ach, "\r\n");
  97. OutputDebugStringA(ach);
  98. if (fDebugBreak)
  99. DebugBreak();
  100. } // DbgVPrintF()
  101. //--------------------------------------------------------------------------;
  102. //
  103. // void dprintf(UINT uDbgLevel, LPSTR szFmt, ...)
  104. //
  105. // Description:
  106. // dprintf() is called by the DPF macro if DEBUG is defined at compile
  107. // time.
  108. //
  109. // The messages will be send to COM1: like any debug message. To
  110. // enable debug output, add the following to WIN.INI :
  111. //
  112. // [debug]
  113. // ICSAMPLE=1
  114. //
  115. // Arguments:
  116. //
  117. // Return (void):
  118. //
  119. //
  120. // History:
  121. // 11/23/92
  122. //
  123. //--------------------------------------------------------------------------;
  124. void FAR CDECL dprintf(UINT uDbgLevel, LPSTR szFmt, ...)
  125. {
  126. va_list va;
  127. if (!__gfDbgEnabled || (__guDbgLevel < uDbgLevel))
  128. return;
  129. va_start(va, szFmt);
  130. DbgVPrintF(szFmt, va);
  131. va_end(va);
  132. } // dprintf()
  133. //--------------------------------------------------------------------------;
  134. //
  135. // BOOL DbgEnable(BOOL fEnable)
  136. //
  137. // Description:
  138. //
  139. //
  140. // Arguments:
  141. //
  142. // Return (BOOL):
  143. //
  144. //
  145. // History:
  146. // 11/28/92
  147. //
  148. //--------------------------------------------------------------------------;
  149. BOOL WINAPI DbgEnable(BOOL fEnable)
  150. {
  151. BOOL fOldState;
  152. fOldState = __gfDbgEnabled;
  153. __gfDbgEnabled = fEnable;
  154. return (fOldState);
  155. } // DbgEnable()
  156. //--------------------------------------------------------------------------;
  157. //
  158. // UINT DbgSetLevel(UINT uLevel)
  159. //
  160. // Description:
  161. //
  162. //
  163. // Arguments:
  164. //
  165. // Return (UINT):
  166. //
  167. //
  168. // History:
  169. // 11/24/92
  170. //
  171. //--------------------------------------------------------------------------;
  172. UINT WINAPI DbgSetLevel(UINT uLevel)
  173. {
  174. UINT uOldLevel;
  175. uOldLevel = __guDbgLevel;
  176. __guDbgLevel = uLevel;
  177. return (uOldLevel);
  178. } // DbgSetLevel()
  179. //--------------------------------------------------------------------------;
  180. //
  181. // UINT DbgInitialize(void)
  182. //
  183. // Description:
  184. //
  185. //
  186. // Arguments:
  187. //
  188. // Return (UINT):
  189. //
  190. //
  191. // History:
  192. // 11/24/92
  193. //
  194. //--------------------------------------------------------------------------;
  195. UINT WINAPI DbgInitialize(BOOL fEnable)
  196. {
  197. DbgSetLevel(GetProfileIntA(DEBUG_SECTION, DEBUG_MODULE_NAME, 0));
  198. DbgEnable(fEnable);
  199. return (__guDbgLevel);
  200. } // DbgInitialize()
  201. #endif // #ifdef DEBUG