Leaked source code of windows server 2003
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.

186 lines
4.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 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 DEBUG
  32. #define USE_DDASSERT
  33. #ifndef START_STR
  34. #define START_STR "DDRAW: "
  35. #endif
  36. #ifndef PROF_SECT
  37. #define PROF_SECT "DirectDraw"
  38. #endif
  39. #define END_STR "\r\n"
  40. HWND hWndListBox;
  41. LONG lDebugLevel = 0;
  42. /*
  43. * dumpStr
  44. */
  45. static void dumpStr( LPSTR str )
  46. {
  47. OutputDebugStringA( str );
  48. #ifdef DPF_HWND
  49. if( hWndListBox != NULL )
  50. {
  51. if( !IsWindow( hWndListBox ) )
  52. {
  53. hWndListBox = NULL;
  54. }
  55. }
  56. if( hWndListBox != NULL )
  57. {
  58. UINT sel;
  59. int len;
  60. len = strlen( str );
  61. if( len > 0 )
  62. {
  63. if( str[len-1] == '\r' || str[len-1] == '\n' )
  64. {
  65. str[len-1] = 0;
  66. }
  67. if( len > 1 )
  68. {
  69. if( str[len-2] == '\r' || str[len-2] == '\n' )
  70. {
  71. str[len-2] = 0;
  72. }
  73. }
  74. }
  75. SendMessage( hWndListBox, LB_ADDSTRING, 0, (LONG) (LPSTR) str );
  76. sel = (UINT) SendMessage( hWndListBox, LB_GETCOUNT, 0, 0L );
  77. if( sel != LB_ERR )
  78. {
  79. SendMessage( hWndListBox, LB_SETCURSEL, sel-1, 0L );
  80. }
  81. }
  82. #endif
  83. } /* dumpStr */
  84. /*
  85. * dprintf
  86. */
  87. void cdecl dprintf( UINT lvl, LPSTR szFormat, ...)
  88. {
  89. char str[256];
  90. BOOL allow = FALSE;
  91. va_list ap;
  92. va_start(ap,szFormat);
  93. if( lDebugLevel < 0 )
  94. {
  95. #ifndef WIN95
  96. if( (UINT) abs( lDebugLevel ) == lvl )
  97. #else
  98. if( (UINT) labs( lDebugLevel ) == lvl )
  99. #endif
  100. {
  101. allow = TRUE;
  102. }
  103. }
  104. else if( (UINT) lDebugLevel >= lvl )
  105. {
  106. allow = TRUE;
  107. }
  108. if( allow )
  109. {
  110. wsprintfA( (LPSTR) str, START_STR );
  111. wvsprintfA( str+lstrlenA( str ), szFormat, ap); //(LPVOID)(&szFormat+1) );
  112. lstrcatA( (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 = GetProfileIntA( PROF_SECT, "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. wsprintfA( 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( GetProfileIntA( PROF_SECT, 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