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.

297 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
  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. #if DBG
  110. DebugBreak();
  111. #endif
  112. }
  113. } // DbgVPrintF()
  114. //--------------------------------------------------------------------------;
  115. //
  116. // void dprintf
  117. //
  118. // Description:
  119. // dprintf() is called by the DPF() macro if DEBUG is defined at compile
  120. // time. It is recommended that you only use the DPF() macro to call
  121. // this function--so you don't have to put #ifdef DEBUG around all
  122. // of your code.
  123. //
  124. // Arguments:
  125. // UINT uDbgLevel:
  126. //
  127. // LPSTR szFormat:
  128. //
  129. // Return (void):
  130. // No value is returned.
  131. //
  132. //--------------------------------------------------------------------------;
  133. void FAR CDECL dprintf
  134. (
  135. UINT uDbgLevel,
  136. LPSTR szFormat,
  137. ...
  138. )
  139. {
  140. va_list va;
  141. if (!__gfDbgEnabled || (__guDbgLevel < uDbgLevel))
  142. return;
  143. va_start(va, szFormat);
  144. DbgVPrintF(szFormat, va);
  145. va_end(va);
  146. } // dprintf()
  147. //--------------------------------------------------------------------------;
  148. //
  149. // BOOL DbgEnable
  150. //
  151. // Description:
  152. //
  153. //
  154. // Arguments:
  155. // BOOL fEnable:
  156. //
  157. // Return (BOOL):
  158. // Returns the previous debugging state.
  159. //
  160. //--------------------------------------------------------------------------;
  161. BOOL WINAPI DbgEnable
  162. (
  163. BOOL fEnable
  164. )
  165. {
  166. BOOL fOldState;
  167. fOldState = __gfDbgEnabled;
  168. __gfDbgEnabled = fEnable;
  169. return (fOldState);
  170. } // DbgEnable()
  171. //--------------------------------------------------------------------------;
  172. //
  173. // UINT DbgSetLevel
  174. //
  175. // Description:
  176. //
  177. //
  178. // Arguments:
  179. // UINT uLevel:
  180. //
  181. // Return (UINT):
  182. // Returns the previous debugging level.
  183. //
  184. //--------------------------------------------------------------------------;
  185. UINT WINAPI DbgSetLevel
  186. (
  187. UINT uLevel
  188. )
  189. {
  190. UINT uOldLevel;
  191. uOldLevel = __guDbgLevel;
  192. __guDbgLevel = uLevel;
  193. return (uOldLevel);
  194. } // DbgSetLevel()
  195. //--------------------------------------------------------------------------;
  196. //
  197. // UINT DbgGetLevel
  198. //
  199. // Description:
  200. //
  201. //
  202. // Arguments:
  203. // None.
  204. //
  205. // Return (UINT):
  206. // Returns the current debugging level.
  207. //
  208. //--------------------------------------------------------------------------;
  209. UINT WINAPI DbgGetLevel
  210. (
  211. void
  212. )
  213. {
  214. return (__guDbgLevel);
  215. } // DbgGetLevel()
  216. //--------------------------------------------------------------------------;
  217. //
  218. // UINT DbgInitialize
  219. //
  220. // Description:
  221. //
  222. //
  223. // Arguments:
  224. // BOOL fEnable:
  225. //
  226. // Return (UINT):
  227. // Returns the debugging level that was set.
  228. //
  229. //--------------------------------------------------------------------------;
  230. UINT WINAPI DbgInitialize
  231. (
  232. BOOL fEnable
  233. )
  234. {
  235. UINT uLevel;
  236. uLevel = GetProfileIntA(DEBUG_SECTION, DEBUG_MODULE_NAME, (UINT)-1);
  237. if ((UINT)-1 == uLevel)
  238. {
  239. //
  240. // if the debug key is not present, then force debug output to
  241. // be disabled. this way running a debug version of a component
  242. // on a non-debugging machine will not generate output unless
  243. // the debug key exists.
  244. //
  245. uLevel = 0;
  246. fEnable = FALSE;
  247. }
  248. DbgSetLevel(uLevel);
  249. DbgEnable(fEnable);
  250. return (__guDbgLevel);
  251. } // DbgInitialize()
  252. #endif // #ifdef DEBUG