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.

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