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.

229 lines
5.6 KiB

  1. #undef WIN32_LEAN_AND_MEAN
  2. #define WIN32_LEAN_AND_MEAN
  3. #include <windows.h>
  4. #include "dpf.h"
  5. #include <stdarg.h>
  6. //#ifdef WINNT
  7. //int abs(int x)
  8. //{
  9. // return x>=0?x:-x;
  10. //}
  11. //#endif
  12. #ifdef DEBUG
  13. #define USE_DDASSERT
  14. #ifndef START_STR
  15. #define START_STR "DDRAW: "
  16. #endif
  17. #ifndef PROF_SECT
  18. #define PROF_SECT "DirectDraw"
  19. #endif
  20. #define END_STR "\r\n"
  21. HWND hWndListBox;
  22. LONG lDebugLevel = 0;
  23. /*
  24. * dumpStr
  25. */
  26. static void dumpStr( LPSTR str )
  27. {
  28. OutputDebugString( str );
  29. #ifdef DPF_HWND
  30. if( hWndListBox != NULL )
  31. {
  32. if( !IsWindow( hWndListBox ) )
  33. {
  34. hWndListBox = NULL;
  35. }
  36. }
  37. if( hWndListBox != NULL )
  38. {
  39. UINT sel;
  40. int len;
  41. len = strlen( str );
  42. if( len > 0 )
  43. {
  44. if( str[len-1] == '\r' || str[len-1] == '\n' )
  45. {
  46. str[len-1] = 0;
  47. }
  48. if( len > 1 )
  49. {
  50. if( str[len-2] == '\r' || str[len-2] == '\n' )
  51. {
  52. str[len-2] = 0;
  53. }
  54. }
  55. }
  56. SendMessage( hWndListBox, LB_ADDSTRING, 0, (LONG) (LPSTR) str );
  57. sel = (UINT) SendMessage( hWndListBox, LB_GETCOUNT, 0, 0L );
  58. if( sel != LB_ERR )
  59. {
  60. SendMessage( hWndListBox, LB_SETCURSEL, sel-1, 0L );
  61. }
  62. }
  63. #endif
  64. } /* dumpStr */
  65. /*
  66. * DXdprintf
  67. */
  68. void cdecl DXdprintf( UINT lvl, LPSTR szFormat, ...)
  69. {
  70. char str[256];
  71. //char str2[256];
  72. BOOL allow = FALSE;
  73. va_list ap;
  74. va_start(ap,szFormat);
  75. if( lDebugLevel < 0 )
  76. {
  77. if( (UINT) -lDebugLevel == lvl )
  78. {
  79. allow = TRUE;
  80. }
  81. }
  82. else if( (UINT) lDebugLevel >= lvl )
  83. {
  84. allow = TRUE;
  85. }
  86. if( allow )
  87. {
  88. wsprintf( (LPSTR) str, START_STR );
  89. //GetModuleFileName(NULL,str2,256);
  90. //if (strrchr(str2,'\\'))
  91. // wsprintf(str+strlen(str),"%12s",strrchr(str2,'\\')+1);
  92. //strcat(str,":");
  93. wvsprintf( str+lstrlen( str ), szFormat, ap); //(LPVOID)(&szFormat+1) );
  94. lstrcat( (LPSTR) str, END_STR );
  95. dumpStr( str );
  96. }
  97. va_end(ap);
  98. } /* DXdprintf */
  99. static void cdecl D3Dprintf( UINT lvl, LPSTR msgType, LPSTR szFormat, va_list ap)
  100. {
  101. char str[256];
  102. //char str2[256];
  103. BOOL allow = FALSE;
  104. if( lDebugLevel < 0 )
  105. {
  106. if( (UINT) -lDebugLevel == lvl )
  107. {
  108. allow = TRUE;
  109. }
  110. }
  111. else if( (UINT) lDebugLevel >= lvl )
  112. {
  113. allow = TRUE;
  114. }
  115. if( allow )
  116. {
  117. wsprintf( (LPSTR) str, START_STR );
  118. wsprintf( (LPSTR) str+lstrlen( str ), msgType );
  119. wvsprintf( str+lstrlen( str ), szFormat, ap); //(LPVOID)(&szFormat+1) );
  120. lstrcat( (LPSTR) str, END_STR );
  121. dumpStr( str );
  122. }
  123. } /* D3Dprintf */
  124. void cdecl D3DInfoPrintf( UINT lvl, LPSTR szFormat, ...)
  125. {
  126. va_list ap;
  127. va_start(ap, szFormat);
  128. D3Dprintf(lvl, "(INFO) :", szFormat, ap);
  129. va_end(ap);
  130. }
  131. void cdecl D3DWarnPrintf( UINT lvl, LPSTR szFormat, ...)
  132. {
  133. va_list ap;
  134. va_start(ap,szFormat);
  135. D3Dprintf(lvl, "(WARN) :", szFormat, ap);
  136. va_end(ap);
  137. }
  138. void cdecl D3DErrorPrintf( LPSTR szFormat, ...)
  139. {
  140. va_list ap;
  141. va_start(ap,szFormat);
  142. D3Dprintf(0, "(ERROR) :", szFormat, ap);
  143. va_end(ap);
  144. }
  145. /*
  146. * DPFInit
  147. */
  148. void DPFInit( void )
  149. {
  150. lDebugLevel = GetProfileInt( PROF_SECT, "debug", 0 );
  151. } /* DPFInit */
  152. #ifdef USE_DDASSERT
  153. /*
  154. * NOTE: I don't want to get into error checking for buffer overflows when
  155. * trying to issue an assertion failure message. So instead I just allocate
  156. * a buffer that is "bug enough" (I know, I know...)
  157. */
  158. #define ASSERT_BUFFER_SIZE 512
  159. #define ASSERT_BANNER_STRING "************************************************************"
  160. #define ASSERT_BREAK_SECTION "BreakOnAssert"
  161. #define ASSERT_BREAK_DEFAULT FALSE
  162. #define ASSERT_MESSAGE_LEVEL 0
  163. void _DDAssert( LPCSTR szFile, int nLine, LPCSTR szCondition )
  164. {
  165. char buffer[ASSERT_BUFFER_SIZE];
  166. /*
  167. * Build the debug stream message.
  168. */
  169. wsprintf( buffer, "ASSERTION FAILED! File %s Line %d: %s", szFile, nLine, szCondition );
  170. /*
  171. * Actually issue the message. These messages are considered error level
  172. * so they all go out at error level priority.
  173. */
  174. DXdprintf( ASSERT_MESSAGE_LEVEL, ASSERT_BANNER_STRING );
  175. DXdprintf( ASSERT_MESSAGE_LEVEL, buffer );
  176. DXdprintf( ASSERT_MESSAGE_LEVEL, ASSERT_BANNER_STRING );
  177. /*
  178. * Should we drop into the debugger?
  179. */
  180. if( GetProfileInt( PROF_SECT, ASSERT_BREAK_SECTION, ASSERT_BREAK_DEFAULT ) )
  181. {
  182. /*
  183. * Into the debugger we go...
  184. */
  185. DEBUG_BREAK();
  186. }
  187. }
  188. #endif /* USE_DDASSERT */
  189. #endif