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.

198 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. *@@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. * dprintf
  94. */
  95. void cdecl dprintf( 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. } /* dprintf */
  126. /*
  127. * DPFInit
  128. */
  129. void DPFInit( void )
  130. {
  131. lDebugLevel = GetProfileInt( PROF_SECT, "debug", 0 );
  132. } /* DPFInit */
  133. #ifdef USE_DDASSERT
  134. /*
  135. * NOTE: I don't want to get into error checking for buffer overflows when
  136. * trying to issue an assertion failure message. So instead I just allocate
  137. * a buffer that is "bug enough" (I know, I know...)
  138. */
  139. #define ASSERT_BUFFER_SIZE 512
  140. #define ASSERT_BANNER_STRING "************************************************************"
  141. #define ASSERT_BREAK_SECTION "BreakOnAssert"
  142. #define ASSERT_BREAK_DEFAULT FALSE
  143. #define ASSERT_MESSAGE_LEVEL 0
  144. void _DDAssert( LPCSTR szFile, int nLine, LPCSTR szCondition )
  145. {
  146. char buffer[ASSERT_BUFFER_SIZE];
  147. /*
  148. * Build the debug stream message.
  149. */
  150. wsprintf( buffer, "ASSERTION FAILED! File %s Line %d: %s", szFile, nLine, szCondition );
  151. /*
  152. * Actually issue the message. These messages are considered error level
  153. * so they all go out at error level priority.
  154. */
  155. dprintf( ASSERT_MESSAGE_LEVEL, ASSERT_BANNER_STRING );
  156. dprintf( ASSERT_MESSAGE_LEVEL, buffer );
  157. dprintf( ASSERT_MESSAGE_LEVEL, ASSERT_BANNER_STRING );
  158. /*
  159. * Should we drop into the debugger?
  160. */
  161. if( GetProfileInt( PROF_SECT, ASSERT_BREAK_SECTION, ASSERT_BREAK_DEFAULT ) )
  162. {
  163. /*
  164. * Into the debugger we go...
  165. */
  166. DEBUG_BREAK();
  167. }
  168. }
  169. #endif /* USE_DDASSERT */
  170. #endif
  171. #endif //use new dpf