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.

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