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.

189 lines
4.3 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 dprintf 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 DEBUG
  34. #define USE_DDASSERT
  35. extern char * __pszDpfName;
  36. #ifndef START_STR
  37. #define START_STR "DDRAW: "
  38. #endif
  39. #ifndef PROF_SECT
  40. #define PROF_SECT "DirectDraw"
  41. #endif
  42. #define END_STR "\r\n"
  43. HWND hWndListBox;
  44. LONG lDebugLevel = 0;
  45. /*
  46. * dumpStr
  47. */
  48. static void dumpStr( LPSTR str )
  49. {
  50. OutputDebugString( str );
  51. #ifdef DPF_HWND
  52. if( hWndListBox != NULL )
  53. {
  54. if( !IsWindow( hWndListBox ) )
  55. {
  56. hWndListBox = NULL;
  57. }
  58. }
  59. if( hWndListBox != NULL )
  60. {
  61. UINT sel;
  62. int len;
  63. len = strlen( str );
  64. if( len > 0 )
  65. {
  66. if( str[len-1] == '\r' || str[len-1] == '\n' )
  67. {
  68. str[len-1] = 0;
  69. }
  70. if( len > 1 )
  71. {
  72. if( str[len-2] == '\r' || str[len-2] == '\n' )
  73. {
  74. str[len-2] = 0;
  75. }
  76. }
  77. }
  78. SendMessage( hWndListBox, LB_ADDSTRING, 0, (LONG) (LPSTR) str );
  79. sel = (UINT) SendMessage( hWndListBox, LB_GETCOUNT, 0, 0L );
  80. if( sel != LB_ERR )
  81. {
  82. SendMessage( hWndListBox, LB_SETCURSEL, sel-1, 0L );
  83. }
  84. }
  85. #endif
  86. } /* dumpStr */
  87. /*
  88. * dprintf
  89. */
  90. void cdecl dprintf( UINT lvl, LPSTR szFormat, ...)
  91. {
  92. char str[256];
  93. //char str2[256];
  94. BOOL allow = FALSE;
  95. va_list ap;
  96. va_start(ap,szFormat);
  97. if( lDebugLevel < 0 )
  98. {
  99. if( (UINT) -lDebugLevel == lvl )
  100. {
  101. allow = TRUE;
  102. }
  103. }
  104. else if( (UINT) lDebugLevel >= lvl )
  105. {
  106. allow = TRUE;
  107. }
  108. if( allow )
  109. {
  110. wsprintf ((LPSTR)str, "%s:", __pszDpfName);
  111. wvsprintf( str+lstrlen( str ), szFormat, ap); //(LPVOID)(&szFormat+1) );
  112. lstrcat( (LPSTR) str, END_STR );
  113. dumpStr( str );
  114. }
  115. va_end(ap);
  116. } /* dprintf */
  117. /*
  118. * DPFInit
  119. */
  120. void DPFInit( void )
  121. {
  122. lDebugLevel = GetProfileInt( __pszDpfName, "debug", 0 );
  123. } /* DPFInit */
  124. #ifdef USE_DDASSERT
  125. /*
  126. * NOTE: I don't want to get into error checking for buffer overflows when
  127. * trying to issue an assertion failure message. So instead I just allocate
  128. * a buffer that is "bug enough" (I know, I know...)
  129. */
  130. #define ASSERT_BUFFER_SIZE 512
  131. #define ASSERT_BANNER_STRING "************************************************************"
  132. #define ASSERT_BREAK_SECTION "BreakOnAssert"
  133. #define ASSERT_BREAK_DEFAULT FALSE
  134. #define ASSERT_MESSAGE_LEVEL 0
  135. void _DDAssert( LPCSTR szFile, int nLine, LPCSTR szCondition )
  136. {
  137. char buffer[ASSERT_BUFFER_SIZE];
  138. /*
  139. * Build the debug stream message.
  140. */
  141. wsprintf( buffer, "ASSERTION FAILED! File %s Line %d: %s", szFile, nLine, szCondition );
  142. /*
  143. * Actually issue the message. These messages are considered error level
  144. * so they all go out at error level priority.
  145. */
  146. dprintf( ASSERT_MESSAGE_LEVEL, ASSERT_BANNER_STRING );
  147. dprintf( ASSERT_MESSAGE_LEVEL, buffer );
  148. dprintf( ASSERT_MESSAGE_LEVEL, ASSERT_BANNER_STRING );
  149. /*
  150. * Should we drop into the debugger?
  151. */
  152. if( GetProfileInt( __pszDpfName, ASSERT_BREAK_SECTION, ASSERT_BREAK_DEFAULT ) )
  153. {
  154. /*
  155. * Into the debugger we go...
  156. */
  157. DEBUG_BREAK();
  158. }
  159. }
  160. #endif /* USE_DDASSERT */
  161. #endif
  162. #endif //use new dpf