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.

344 lines
7.7 KiB

  1. // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
  2. // ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
  3. // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
  4. // PARTICULAR PURPOSE.
  5. //
  6. // Copyright 1996-2003 Microsoft Corporation. All Rights Reserved.
  7. //
  8. // FILE: Debug.cpp
  9. //
  10. //
  11. // PURPOSE: Debug functions.
  12. //
  13. //
  14. // Functions:
  15. //
  16. //
  17. //
  18. // PLATFORMS: Windows 2000, Windows XP, Windows Server 2003
  19. //
  20. //
  21. #include "precomp.h"
  22. #include "oem.h"
  23. #include "debug.h"
  24. #include "kmode.h"
  25. #include <strsafe.h>
  26. ////////////////////////////////////////////////////////
  27. // INTERNAL DEFINES
  28. ////////////////////////////////////////////////////////
  29. #define DEBUG_BUFFER_SIZE 1024
  30. #define PATH_SEPARATOR '\\'
  31. // Determine what level of debugging messages to eject.
  32. #ifdef VERBOSE_MSG
  33. #define DEBUG_LEVEL DBG_VERBOSE
  34. #elif TERSE_MSG
  35. #define DEBUG_LEVEL DBG_TERSE
  36. #elif WARNING_MSG
  37. #define DEBUG_LEVEL DBG_WARNING
  38. #elif ERROR_MSG
  39. #define DEBUG_LEVEL DBG_ERROR
  40. #elif RIP_MSG
  41. #define DEBUG_LEVEL DBG_RIP
  42. #elif NO_DBG_MSG
  43. #define DEBUG_LEVEL DBG_NONE
  44. #else
  45. #define DEBUG_LEVEL DBG_WARNING
  46. #endif
  47. ////////////////////////////////////////////////////////
  48. // EXTERNAL GLOBALS
  49. ////////////////////////////////////////////////////////
  50. INT giDebugLevel = DEBUG_LEVEL;
  51. ////////////////////////////////////////////////////////
  52. // INTERNAL PROTOTYPES
  53. ////////////////////////////////////////////////////////
  54. static BOOL DebugMessageV(LPCSTR lpszMessage, va_list arglist);
  55. static BOOL DebugMessageV(DWORD dwSize, LPCWSTR lpszMessage, va_list arglist);
  56. //////////////////////////////////////////////////////////////////////////
  57. // Function: DebugMessageV
  58. //
  59. // Description: Outputs variable argument debug string.
  60. //
  61. //
  62. // Parameters:
  63. //
  64. // dwSize Size of temp buffer to hold formated string.
  65. //
  66. // lpszMessage Format string.
  67. //
  68. // arglist Variable argument list..
  69. //
  70. //
  71. // Returns:
  72. //
  73. //
  74. // Comments:
  75. //
  76. //
  77. // History:
  78. // 12/18/96 APresley Created.
  79. //
  80. //////////////////////////////////////////////////////////////////////////
  81. static BOOL DebugMessageV(LPCSTR lpszMessage, va_list arglist)
  82. {
  83. DWORD dwSize = DEBUG_BUFFER_SIZE;
  84. LPSTR lpszMsgBuf = NULL;
  85. HRESULT hr = S_FALSE;
  86. // Parameter checking.
  87. if( (NULL == lpszMessage)
  88. ||
  89. (0 == dwSize)
  90. )
  91. {
  92. return FALSE;
  93. }
  94. do
  95. {
  96. // Allocate memory for message buffer.
  97. if(NULL != lpszMsgBuf)
  98. {
  99. delete[] lpszMsgBuf;
  100. dwSize *= 2;
  101. }
  102. //
  103. // Just to make sure we dont go into infinite loop and allocate
  104. // lots of memory, lets bail out if memory requirement becomes huge.
  105. // Multiplying by 8, i.e. will loop at most 4 times.
  106. //
  107. if ( dwSize > 8*DEBUG_BUFFER_SIZE )
  108. {
  109. return FALSE;
  110. }
  111. lpszMsgBuf = new CHAR[dwSize + 1];
  112. if(NULL == lpszMsgBuf)
  113. return FALSE;
  114. hr = StringCchVPrintfA ( lpszMsgBuf, dwSize, lpszMessage, arglist);
  115. // Pass the variable parameters to wvsprintf to be formated.
  116. } while (FAILED (hr) );
  117. // Dump string to Debug output.
  118. OutputDebugStringA(lpszMsgBuf);
  119. // Cleanup.
  120. delete[] lpszMsgBuf;
  121. return TRUE;
  122. }
  123. //////////////////////////////////////////////////////////////////////////
  124. // Function: DebugMessageV
  125. //
  126. // Description: Outputs variable argument debug string.
  127. //
  128. //
  129. // Parameters:
  130. //
  131. // dwSize Size of temp buffer to hold formated string.
  132. //
  133. // lpszMessage Format string.
  134. //
  135. // arglist Variable argument list..
  136. //
  137. //
  138. // Returns:
  139. //
  140. //
  141. // Comments:
  142. //
  143. //
  144. // History:
  145. // 12/18/96 APresley Created.
  146. //
  147. //////////////////////////////////////////////////////////////////////////
  148. static BOOL DebugMessageV(DWORD dwSize, LPCWSTR lpszMessage, va_list arglist)
  149. {
  150. LPWSTR lpszMsgBuf;
  151. HRESULT hr = S_FALSE;
  152. // Parameter checking.
  153. if( (NULL == lpszMessage)
  154. ||
  155. (0 == dwSize)
  156. )
  157. {
  158. return FALSE;
  159. }
  160. // Allocate memory for message buffer.
  161. lpszMsgBuf = new WCHAR[dwSize + 1];
  162. if(NULL == lpszMsgBuf)
  163. return FALSE;
  164. // Pass the variable parameters to wvsprintf to be formated.
  165. hr = StringCchVPrintfW (lpszMsgBuf, dwSize, lpszMessage, arglist);
  166. if ( SUCCEEDED (hr) )
  167. {
  168. // Dump string to debug output.
  169. OutputDebugStringW(lpszMsgBuf);
  170. }
  171. // Clean up.
  172. delete[] lpszMsgBuf;
  173. return TRUE;
  174. }
  175. //////////////////////////////////////////////////////////////////////////
  176. // Function: DebugMessage
  177. //
  178. // Description: Outputs variable argument debug string.
  179. //
  180. //
  181. // Parameters:
  182. //
  183. // lpszMessage Format string.
  184. //
  185. //
  186. // Returns:
  187. //
  188. //
  189. // Comments:
  190. //
  191. //
  192. // History:
  193. // 12/18/96 APresley Created.
  194. //
  195. //////////////////////////////////////////////////////////////////////////
  196. BOOL DebugMessage(LPCSTR lpszMessage, ...)
  197. {
  198. BOOL bResult;
  199. va_list VAList;
  200. // Pass the variable parameters to DebugMessageV for processing.
  201. va_start(VAList, lpszMessage);
  202. bResult = DebugMessageV(lpszMessage, VAList);
  203. va_end(VAList);
  204. return bResult;
  205. }
  206. //////////////////////////////////////////////////////////////////////////
  207. // Function: DebugMessage
  208. //
  209. // Description: Outputs variable argument debug string.
  210. //
  211. //
  212. // Parameters:
  213. //
  214. // lpszMessage Format string.
  215. //
  216. //
  217. // Returns:
  218. //
  219. //
  220. // Comments:
  221. //
  222. //
  223. // History:
  224. // 12/18/96 APresley Created.
  225. //
  226. //////////////////////////////////////////////////////////////////////////
  227. BOOL DebugMessage(LPCWSTR lpszMessage, ...)
  228. {
  229. BOOL bResult;
  230. va_list VAList;
  231. // Pass the variable parameters to DebugMessageV to be processed.
  232. va_start(VAList, lpszMessage);
  233. bResult = DebugMessageV(MAX_PATH, lpszMessage, VAList);
  234. va_end(VAList);
  235. return bResult;
  236. }
  237. void Dump(PPUBLISHERINFO pPublisherInfo)
  238. {
  239. VERBOSE(__TEXT("pPublisherInfo:\r\n"));
  240. VERBOSE(__TEXT("\tdwMode = %#x\r\n"), pPublisherInfo->dwMode);
  241. VERBOSE(__TEXT("\twMinoutlinePPEM = %d\r\n"), pPublisherInfo->wMinoutlinePPEM);
  242. VERBOSE(__TEXT("\twMaxbitmapPPEM = %d\r\n"), pPublisherInfo->wMaxbitmapPPEM);
  243. }
  244. void Dump(POEMDMPARAM pOemDMParam)
  245. {
  246. VERBOSE(__TEXT("pOemDMParam:\r\n"));
  247. VERBOSE(__TEXT("\tcbSize = %d\r\n"), pOemDMParam->cbSize);
  248. VERBOSE(__TEXT("\tpdriverobj = %#x\r\n"), pOemDMParam->pdriverobj);
  249. VERBOSE(__TEXT("\thPrinter = %#x\r\n"), pOemDMParam->hPrinter);
  250. VERBOSE(__TEXT("\thModule = %#x\r\n"), pOemDMParam->hModule);
  251. VERBOSE(__TEXT("\tpPublicDMIn = %#x\r\n"), pOemDMParam->pPublicDMIn);
  252. VERBOSE(__TEXT("\tpPublicDMOut = %#x\r\n"), pOemDMParam->pPublicDMOut);
  253. VERBOSE(__TEXT("\tpOEMDMIn = %#x\r\n"), pOemDMParam->pOEMDMIn);
  254. VERBOSE(__TEXT("\tpOEMDMOut = %#x\r\n"), pOemDMParam->pOEMDMOut);
  255. VERBOSE(__TEXT("\tcbBufSize = %d\r\n"), pOemDMParam->cbBufSize);
  256. }
  257. PCSTR
  258. StripDirPrefixA(
  259. IN PCSTR pstrFilename
  260. )
  261. /*++
  262. Routine Description:
  263. Strip the directory prefix off a filename (ANSI version)
  264. Arguments:
  265. pstrFilename - Pointer to filename string
  266. Return Value:
  267. Pointer to the last component of a filename (without directory prefix)
  268. --*/
  269. {
  270. PCSTR pstr;
  271. if (pstr = strrchr(pstrFilename, PATH_SEPARATOR))
  272. return pstr + 1;
  273. return pstrFilename;
  274. }