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.

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