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.

289 lines
7.8 KiB

  1. /*==========================================================================
  2. *
  3. * Copyright (C) 1994-1995 Microsoft Corporation. All Rights Reserved.
  4. *
  5. * File: dpf.c
  6. * Content: debugging printf
  7. *@@BEGIN_MSINTERNAL
  8. * History:
  9. * Date By Reason
  10. * ==== == ======
  11. * 06-jan-95 craige initial implementation
  12. * 03-mar-95 craige added dprintf2
  13. * 31-mar-95 craige add DPFInit to read WIN.INI for [DirectDraw] section;
  14. * added dprintf3
  15. * 01-apr-95 craige happy fun joy updated header file
  16. * 06-apr-95 craige made stand-alone
  17. * 18-jun-95 craige use negative dpf level to display ONLY that level
  18. * 06-dec-95 jeffno Changed DXdprintf to use c-standard variable argument
  19. * list techniques. Also added abs for NT
  20. * 06-feb-96 colinmc added simple assertion mechanism for DirectDraw
  21. * 15-apr-96 kipo added msinternal
  22. *@@END_MSINTERNAL
  23. *
  24. ***************************************************************************/
  25. #ifdef NEW_DPF
  26. #include "newdpf.c"
  27. #else //use old debug:
  28. #undef WIN32_LEAN_AND_MEAN
  29. #define WIN32_LEAN_AND_MEAN
  30. #include <windows.h>
  31. #include "dpf.h"
  32. #include <stdarg.h>
  33. //#ifdef WINNT
  34. //int abs(int x)
  35. //{
  36. // return x>=0?x:-x;
  37. //}
  38. //#endif
  39. #ifdef DEBUG
  40. #define USE_DDASSERT
  41. #ifndef START_STR
  42. #define START_STR "DDRAW: "
  43. #endif
  44. #ifndef PROF_SECT
  45. #define PROF_SECT "DirectDraw"
  46. #endif
  47. #define END_STR "\r\n"
  48. HWND hWndListBox;
  49. LONG lDebugLevel = 0;
  50. /*
  51. * dumpStr
  52. */
  53. static void dumpStr( LPSTR str )
  54. {
  55. OutputDebugString( str );
  56. #ifdef DPF_HWND
  57. if( hWndListBox != NULL )
  58. {
  59. if( !IsWindow( hWndListBox ) )
  60. {
  61. hWndListBox = NULL;
  62. }
  63. }
  64. if( hWndListBox != NULL )
  65. {
  66. UINT sel;
  67. int len;
  68. len = strlen( str );
  69. if( len > 0 )
  70. {
  71. if( str[len-1] == '\r' || str[len-1] == '\n' )
  72. {
  73. str[len-1] = 0;
  74. }
  75. if( len > 1 )
  76. {
  77. if( str[len-2] == '\r' || str[len-2] == '\n' )
  78. {
  79. str[len-2] = 0;
  80. }
  81. }
  82. }
  83. SendMessage( hWndListBox, LB_ADDSTRING, 0, (LONG) (LPSTR) str );
  84. sel = (UINT) SendMessage( hWndListBox, LB_GETCOUNT, 0, 0L );
  85. if( sel != LB_ERR )
  86. {
  87. SendMessage( hWndListBox, LB_SETCURSEL, sel-1, 0L );
  88. }
  89. }
  90. #endif
  91. } /* dumpStr */
  92. /*
  93. * DXdprintf
  94. */
  95. void cdecl DXdprintf( UINT lvl, LPSTR szFormat, ...)
  96. {
  97. char str[256];
  98. //char str2[256];
  99. BOOL allow = FALSE;
  100. va_list ap;
  101. va_start(ap,szFormat);
  102. if( lDebugLevel < 0 )
  103. {
  104. if( (UINT) -lDebugLevel == lvl )
  105. {
  106. allow = TRUE;
  107. }
  108. }
  109. else if( (UINT) lDebugLevel >= lvl )
  110. {
  111. allow = TRUE;
  112. }
  113. if( allow )
  114. {
  115. wsprintf( (LPSTR) str, START_STR );
  116. //GetModuleFileName(NULL,str2,256);
  117. //if (strrchr(str2,'\\'))
  118. // wsprintf(str+strlen(str),"%12s",strrchr(str2,'\\')+1);
  119. //strcat(str,":");
  120. #ifdef WIN95
  121. char szTmp[512];
  122. char *psz = szTmp;
  123. strncpy(szTmp, szFormat, 512);
  124. // %p does not work on Windows95.
  125. // We look for each "%p" and substitute 'x' for 'p'
  126. // WARNING: This code does not handle escape sequences using %p.
  127. // Extra code must be added to deal with that case
  128. // if necessary
  129. while (psz = strstr(psz, "%p"))
  130. *(psz+1) = 'x';
  131. wvsprintf( str+lstrlen( str ), szTmp, ap); //(LPVOID)(&szFormat+1) );
  132. #else
  133. wvsprintf( str+lstrlen( str ), szFormat, ap); //(LPVOID)(&szFormat+1) );
  134. #endif //WIN95
  135. lstrcat( (LPSTR) str, END_STR );
  136. dumpStr( str );
  137. }
  138. va_end(ap);
  139. } /* DXdprintf */
  140. static void cdecl D3Dprintf( UINT lvl, LPSTR msgType, LPSTR szFormat, va_list ap)
  141. {
  142. char str[256];
  143. //char str2[256];
  144. BOOL allow = FALSE;
  145. if( lDebugLevel < 0 )
  146. {
  147. if( (UINT) -lDebugLevel == lvl )
  148. {
  149. allow = TRUE;
  150. }
  151. }
  152. else if( (UINT) lDebugLevel >= lvl )
  153. {
  154. allow = TRUE;
  155. }
  156. if( allow )
  157. {
  158. wsprintf( (LPSTR) str, START_STR );
  159. wsprintf( (LPSTR) str+lstrlen( str ), msgType );
  160. #ifdef WIN95
  161. char szTmp[512];
  162. char *psz = szTmp;
  163. strncpy(szTmp, szFormat, 512);
  164. // %p does not work on Windows95.
  165. // We look for each "%p" and substitute 'x' for 'p'
  166. // WARNING: This code does not handle escape sequences using %p.
  167. // Extra code must be added to deal with that case
  168. // if necessary
  169. while (psz = strstr(psz, "%p"))
  170. *(psz+1) = 'x';
  171. wvsprintf( str+lstrlen( str ), szTmp, ap);
  172. #else
  173. wvsprintf( str+lstrlen( str ), szFormat, ap); //(LPVOID)(&szFormat+1) );
  174. #endif // WIN95
  175. lstrcat( (LPSTR) str, END_STR );
  176. dumpStr( str );
  177. }
  178. } /* D3Dprintf */
  179. void cdecl D3DInfoPrintf( UINT lvl, LPSTR szFormat, ...)
  180. {
  181. va_list ap;
  182. va_start(ap, szFormat);
  183. D3Dprintf(lvl, "(INFO) :", szFormat, ap);
  184. va_end(ap);
  185. }
  186. void cdecl D3DWarnPrintf( UINT lvl, LPSTR szFormat, ...)
  187. {
  188. va_list ap;
  189. va_start(ap,szFormat);
  190. D3Dprintf(lvl, "(WARN) :", szFormat, ap);
  191. va_end(ap);
  192. }
  193. void cdecl D3DErrorPrintf( LPSTR szFormat, ...)
  194. {
  195. va_list ap;
  196. va_start(ap,szFormat);
  197. D3Dprintf(0, "(ERROR) :", szFormat, ap);
  198. va_end(ap);
  199. }
  200. /*
  201. * DPFInit
  202. */
  203. void DPFInit( void )
  204. {
  205. lDebugLevel = GetProfileInt( PROF_SECT, "debug", 0 );
  206. } /* DPFInit */
  207. #ifdef USE_DDASSERT
  208. /*
  209. * NOTE: I don't want to get into error checking for buffer overflows when
  210. * trying to issue an assertion failure message. So instead I just allocate
  211. * a buffer that is "bug enough" (I know, I know...)
  212. */
  213. #define ASSERT_BUFFER_SIZE 512
  214. #define ASSERT_BANNER_STRING "************************************************************"
  215. #define ASSERT_BREAK_SECTION "BreakOnAssert"
  216. #define ASSERT_BREAK_DEFAULT FALSE
  217. #define ASSERT_MESSAGE_LEVEL 0
  218. void _DDAssert( LPCSTR szFile, int nLine, LPCSTR szCondition )
  219. {
  220. char buffer[ASSERT_BUFFER_SIZE];
  221. /*
  222. * Build the debug stream message.
  223. */
  224. wsprintf( buffer, "ASSERTION FAILED! File %s Line %d: %s", szFile, nLine, szCondition );
  225. /*
  226. * Actually issue the message. These messages are considered error level
  227. * so they all go out at error level priority.
  228. */
  229. DXdprintf( ASSERT_MESSAGE_LEVEL, ASSERT_BANNER_STRING );
  230. DXdprintf( ASSERT_MESSAGE_LEVEL, buffer );
  231. DXdprintf( ASSERT_MESSAGE_LEVEL, ASSERT_BANNER_STRING );
  232. /*
  233. * Should we drop into the debugger?
  234. */
  235. if( GetProfileInt( PROF_SECT, ASSERT_BREAK_SECTION, ASSERT_BREAK_DEFAULT ) )
  236. {
  237. /*
  238. * Into the debugger we go...
  239. */
  240. DEBUG_BREAK();
  241. }
  242. }
  243. #endif /* USE_DDASSERT */
  244. #endif
  245. #endif //use new dpf