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.

295 lines
6.0 KiB

  1. //==========================================================================;
  2. //
  3. // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
  4. // KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  5. // IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR
  6. // PURPOSE.
  7. //
  8. // Copyright (c) 1992, 1994 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. //
  19. //==========================================================================;
  20. #ifdef DEBUG
  21. #include <windows.h>
  22. #include <windowsx.h>
  23. #include <stdarg.h>
  24. #include "debug.h"
  25. //
  26. // since we don't UNICODE our debugging messages, use the ASCII entry
  27. // points regardless of how we are compiled.
  28. //
  29. #ifdef WIN32
  30. #include <wchar.h>
  31. #else
  32. #define lstrcatA lstrcat
  33. #define lstrlenA lstrlen
  34. #define GetProfileIntA GetProfileInt
  35. #define OutputDebugStringA OutputDebugString
  36. #endif
  37. //
  38. //
  39. //
  40. BOOL __gfDbgEnabled = TRUE; // master enable
  41. UINT __guDbgLevel = 0; // current debug level
  42. //--------------------------------------------------------------------------;
  43. //
  44. // void DbgVPrintF
  45. //
  46. // Description:
  47. //
  48. //
  49. // Arguments:
  50. // LPSTR szFormat:
  51. //
  52. // va_list va:
  53. //
  54. // Return (void):
  55. // No value is returned.
  56. //
  57. //--------------------------------------------------------------------------;
  58. void FAR CDECL DbgVPrintF
  59. (
  60. LPSTR szFormat,
  61. va_list va
  62. )
  63. {
  64. char ach[DEBUG_MAX_LINE_LEN];
  65. BOOL fDebugBreak = FALSE;
  66. BOOL fPrefix = TRUE;
  67. BOOL fCRLF = TRUE;
  68. ach[0] = '\0';
  69. for (;;)
  70. {
  71. switch (*szFormat)
  72. {
  73. case '!':
  74. fDebugBreak = TRUE;
  75. szFormat++;
  76. continue;
  77. case '`':
  78. fPrefix = FALSE;
  79. szFormat++;
  80. continue;
  81. case '~':
  82. fCRLF = FALSE;
  83. szFormat++;
  84. continue;
  85. }
  86. break;
  87. }
  88. if (fDebugBreak)
  89. {
  90. ach[0] = '\007';
  91. ach[1] = '\0';
  92. }
  93. if (fPrefix)
  94. {
  95. lstrcatA(ach, DEBUG_MODULE_NAME ": ");
  96. }
  97. #ifdef WIN32
  98. wvsprintfA(ach + lstrlenA(ach), szFormat, va);
  99. #else
  100. wvsprintf(ach + lstrlenA(ach), szFormat, (LPSTR)va);
  101. #endif
  102. if (fCRLF)
  103. {
  104. lstrcatA(ach, "\r\n");
  105. }
  106. OutputDebugStringA(ach);
  107. if (fDebugBreak)
  108. {
  109. DebugBreak();
  110. }
  111. } // DbgVPrintF()
  112. //--------------------------------------------------------------------------;
  113. //
  114. // void dprintf
  115. //
  116. // Description:
  117. // dprintf() is called by the DPF() macro if DEBUG is defined at compile
  118. // time. It is recommended that you only use the DPF() macro to call
  119. // this function--so you don't have to put #ifdef DEBUG around all
  120. // of your code.
  121. //
  122. // Arguments:
  123. // UINT uDbgLevel:
  124. //
  125. // LPSTR szFormat:
  126. //
  127. // Return (void):
  128. // No value is returned.
  129. //
  130. //--------------------------------------------------------------------------;
  131. void FAR CDECL dprintf
  132. (
  133. UINT uDbgLevel,
  134. LPSTR szFormat,
  135. ...
  136. )
  137. {
  138. va_list va;
  139. if (!__gfDbgEnabled || (__guDbgLevel < uDbgLevel))
  140. return;
  141. va_start(va, szFormat);
  142. DbgVPrintF(szFormat, va);
  143. va_end(va);
  144. } // dprintf()
  145. //--------------------------------------------------------------------------;
  146. //
  147. // BOOL DbgEnable
  148. //
  149. // Description:
  150. //
  151. //
  152. // Arguments:
  153. // BOOL fEnable:
  154. //
  155. // Return (BOOL):
  156. // Returns the previous debugging state.
  157. //
  158. //--------------------------------------------------------------------------;
  159. BOOL WINAPI DbgEnable
  160. (
  161. BOOL fEnable
  162. )
  163. {
  164. BOOL fOldState;
  165. fOldState = __gfDbgEnabled;
  166. __gfDbgEnabled = fEnable;
  167. return (fOldState);
  168. } // DbgEnable()
  169. //--------------------------------------------------------------------------;
  170. //
  171. // UINT DbgSetLevel
  172. //
  173. // Description:
  174. //
  175. //
  176. // Arguments:
  177. // UINT uLevel:
  178. //
  179. // Return (UINT):
  180. // Returns the previous debugging level.
  181. //
  182. //--------------------------------------------------------------------------;
  183. UINT WINAPI DbgSetLevel
  184. (
  185. UINT uLevel
  186. )
  187. {
  188. UINT uOldLevel;
  189. uOldLevel = __guDbgLevel;
  190. __guDbgLevel = uLevel;
  191. return (uOldLevel);
  192. } // DbgSetLevel()
  193. //--------------------------------------------------------------------------;
  194. //
  195. // UINT DbgGetLevel
  196. //
  197. // Description:
  198. //
  199. //
  200. // Arguments:
  201. // None.
  202. //
  203. // Return (UINT):
  204. // Returns the current debugging level.
  205. //
  206. //--------------------------------------------------------------------------;
  207. UINT WINAPI DbgGetLevel
  208. (
  209. void
  210. )
  211. {
  212. return (__guDbgLevel);
  213. } // DbgGetLevel()
  214. //--------------------------------------------------------------------------;
  215. //
  216. // UINT DbgInitialize
  217. //
  218. // Description:
  219. //
  220. //
  221. // Arguments:
  222. // BOOL fEnable:
  223. //
  224. // Return (UINT):
  225. // Returns the debugging level that was set.
  226. //
  227. //--------------------------------------------------------------------------;
  228. UINT WINAPI DbgInitialize
  229. (
  230. BOOL fEnable
  231. )
  232. {
  233. UINT uLevel;
  234. uLevel = GetProfileIntA(DEBUG_SECTION, DEBUG_MODULE_NAME, (UINT)-1);
  235. if ((UINT)-1 == uLevel)
  236. {
  237. //
  238. // if the debug key is not present, then force debug output to
  239. // be disabled. this way running a debug version of a component
  240. // on a non-debugging machine will not generate output unless
  241. // the debug key exists.
  242. //
  243. uLevel = 0;
  244. fEnable = FALSE;
  245. }
  246. DbgSetLevel(uLevel);
  247. DbgEnable(fEnable);
  248. return (__guDbgLevel);
  249. } // DbgInitialize()
  250. #endif // #ifdef DEBUG