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.

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