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.

249 lines
6.5 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. wvsprintf( str+lstrlen( str ), szFormat, ap); //(LPVOID)(&szFormat+1) );
  121. lstrcat( (LPSTR) str, END_STR );
  122. dumpStr( str );
  123. }
  124. va_end(ap);
  125. } /* DXdprintf */
  126. static void cdecl D3Dprintf( UINT lvl, LPSTR msgType, LPSTR szFormat, va_list ap)
  127. {
  128. char str[256];
  129. //char str2[256];
  130. BOOL allow = FALSE;
  131. if( lDebugLevel < 0 )
  132. {
  133. if( (UINT) -lDebugLevel == lvl )
  134. {
  135. allow = TRUE;
  136. }
  137. }
  138. else if( (UINT) lDebugLevel >= lvl )
  139. {
  140. allow = TRUE;
  141. }
  142. if( allow )
  143. {
  144. wsprintf( (LPSTR) str, START_STR );
  145. wsprintf( (LPSTR) str+lstrlen( str ), msgType );
  146. wvsprintf( str+lstrlen( str ), szFormat, ap); //(LPVOID)(&szFormat+1) );
  147. lstrcat( (LPSTR) str, END_STR );
  148. dumpStr( str );
  149. }
  150. } /* D3Dprintf */
  151. void cdecl D3DInfoPrintf( UINT lvl, LPSTR szFormat, ...)
  152. {
  153. va_list ap;
  154. va_start(ap, szFormat);
  155. D3Dprintf(lvl, "(INFO) :", szFormat, ap);
  156. va_end(ap);
  157. }
  158. void cdecl D3DWarnPrintf( UINT lvl, LPSTR szFormat, ...)
  159. {
  160. va_list ap;
  161. va_start(ap,szFormat);
  162. D3Dprintf(lvl, "(WARN) :", szFormat, ap);
  163. va_end(ap);
  164. }
  165. /*
  166. * DPFInit
  167. */
  168. void DPFInit( void )
  169. {
  170. lDebugLevel = GetProfileInt( PROF_SECT, "debug", 0 );
  171. } /* DPFInit */
  172. #ifdef USE_DDASSERT
  173. /*
  174. * NOTE: I don't want to get into error checking for buffer overflows when
  175. * trying to issue an assertion failure message. So instead I just allocate
  176. * a buffer that is "bug enough" (I know, I know...)
  177. */
  178. #define ASSERT_BUFFER_SIZE 512
  179. #define ASSERT_BANNER_STRING "************************************************************"
  180. #define ASSERT_BREAK_SECTION "BreakOnAssert"
  181. #define ASSERT_BREAK_DEFAULT FALSE
  182. #define ASSERT_MESSAGE_LEVEL 0
  183. void _DDAssert( LPCSTR szFile, int nLine, LPCSTR szCondition )
  184. {
  185. char buffer[ASSERT_BUFFER_SIZE];
  186. /*
  187. * Build the debug stream message.
  188. */
  189. wsprintf( buffer, "ASSERTION FAILED! File %s Line %d: %s", szFile, nLine, szCondition );
  190. /*
  191. * Actually issue the message. These messages are considered error level
  192. * so they all go out at error level priority.
  193. */
  194. DXdprintf( ASSERT_MESSAGE_LEVEL, ASSERT_BANNER_STRING );
  195. DXdprintf( ASSERT_MESSAGE_LEVEL, buffer );
  196. DXdprintf( ASSERT_MESSAGE_LEVEL, ASSERT_BANNER_STRING );
  197. /*
  198. * Should we drop into the debugger?
  199. */
  200. if( GetProfileInt( PROF_SECT, ASSERT_BREAK_SECTION, ASSERT_BREAK_DEFAULT ) )
  201. {
  202. /*
  203. * Into the debugger we go...
  204. */
  205. DEBUG_BREAK();
  206. }
  207. }
  208. #endif /* USE_DDASSERT */
  209. #endif
  210. #endif //use new dpf